//
// ViewController.m
// helloworld
//
// Created by apple on 2020/6/15.
// Copyright © 2020 tu. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
int index1=0;
// 控制器的view加载完毕的时候调用
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"%s","打印测试1");
}
//函数
//函数前面的减号 代表一个函数的开始
//objectc没有public和private。
//函数前面的加号 代表可以直接调用这个函数,而不用类的实例
// - (返回类型) 函数名:(参数类型)参数类型
//按钮事件
//在界面选中按钮控件,右键,会弹出这个按钮控件的相关事件列表,然后
// 按住Ctrl键,点击事件右边的加号,拖到代码里面来
- (IBAction)Button1TouchDown:(id)sender {
NSLog(@"%s","Button1TouchDown");
//UILabel* label= [self.view subviews][0];
//获取UIView控件
for(UIView* subView in self.view.subviews)
{
// [实例 方法名:参数] 方法调用
if([ subView isKindOfClass:[UILabel class] ])
{
// NSLog(@"subview= %@",subView); //输出 所有属性
UILabel* uiLabel=(UILabel*)subView;
NSLog(@"text= %@",uiLabel.text);
//根据tag属性找到 label
if( uiLabel.tag==1 )
{
++index1;
NSString* string1=NULL;
string1= [NSString stringWithFormat:@"%d",index1];
string1= [string1 stringByAppendingString:@"修改"];
uiLabel.text=string1;
}
}
}
}
@end