objective-c初级代码
要实现的功能是:Label;显示信息。SetButton;点击在Label上显示一句话.ResetButton:点击清空Label.要用viewcontroller编辑最...
要实现的功能是:Label;显示信息。Set Button;点击在Label上显示一句话.Reset Button:点击清空Label.要用viewcontroller编辑
最好能给解析一下 展开
最好能给解析一下 展开
展开全部
- (void)lableSet
{
lable.text = @"lableSet";
}
- (void)resLable
{
lable.text = @"";
}
-(void)buttonAndLable
{
//button的type
UIButton *setButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//button坐标
setButton.frame = CGRectMake(120, 120, 120, 120);
//button上面子的颜色
[setButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//button上显示子名字
[setButton setTitle:@"set" forState:UIControlStateNormal];
//添加setbutton点击事件 更换lable的text
[setButton addTarget:self action:@selector(lableSet) forControlEvents:UIControlEventTouchUpInside];
//button添加到controller的view上,resbutton同理
[self.view addSubview:setButton];
//添加resButton点击事件 更换lable的text
UIButton *resButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
resButton.frame = CGRectMake(120+120, 120, 120, 120);
[resButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[resButton setTitle:@"reset" forState:UIControlStateNormal];
[resButton addTarget:self action:@selector(resLable) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:resButton];
//lable 是成员变量 在头文件声明的,以便引用它的指针 UILabel *lable;
lable = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 120, 120)];
lable.text = @"hello!";
[self.view addSubview:lable];
}
- (void)viewDidLoad{
[super viewDidLoad];
[self buttonAndLable];
}
{
lable.text = @"lableSet";
}
- (void)resLable
{
lable.text = @"";
}
-(void)buttonAndLable
{
//button的type
UIButton *setButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//button坐标
setButton.frame = CGRectMake(120, 120, 120, 120);
//button上面子的颜色
[setButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//button上显示子名字
[setButton setTitle:@"set" forState:UIControlStateNormal];
//添加setbutton点击事件 更换lable的text
[setButton addTarget:self action:@selector(lableSet) forControlEvents:UIControlEventTouchUpInside];
//button添加到controller的view上,resbutton同理
[self.view addSubview:setButton];
//添加resButton点击事件 更换lable的text
UIButton *resButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
resButton.frame = CGRectMake(120+120, 120, 120, 120);
[resButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[resButton setTitle:@"reset" forState:UIControlStateNormal];
[resButton addTarget:self action:@selector(resLable) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:resButton];
//lable 是成员变量 在头文件声明的,以便引用它的指针 UILabel *lable;
lable = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 120, 120)];
lable.text = @"hello!";
[self.view addSubview:lable];
}
- (void)viewDidLoad{
[super viewDidLoad];
[self buttonAndLable];
}
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
单片机汇编程序是用汇编语言编写的程序,用于控制单片机的操作。汇编语言是一种比较接近计算机硬件语言的低级语言,相对于高级语言来说更容易理解和实现。下面是单片机汇编程序的基本步骤:1. 将代码和数据汇编到规定的段中。2. 在存储器中用未初始化的...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询