如何做才能使点击button2时,button4变换背景颜色?
请尽量清晰完善地描述问题,以便大家给予专业的回复。
15
收起
正在回答 回答被采纳积分+1
2回答
Tender10
2017-11-30 15:55:38
你可以看看如下代码:
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIButton *button2;
@property(nonatomic,strong)UIButton *button4;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.button2 = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
self.button2.backgroundColor = [UIColor redColor];
[self.button2 addTarget:self action:@selector(button2Click) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.button2];
self.button4 = [[UIButton alloc] initWithFrame:CGRectMake(10, 110, 100, 20)];
self.button4.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.button4];
}
- (void)button2Click {
self.button4.backgroundColor = [UIColor greenColor];
}
iOS入门:基础语法与常用控件
- 参与学习 1337 人
- 提交作业 712 份
- 解答问题 1878 个
很多人都在疑问没有基础该怎么学习iOS开发?不用担心,本路径采用游戏关卡式的教学模式,并且以经典OC与最新Swift双重结合的教学内容,帮助大家快速掌握两种iOS开发语言基础,去掉“零”标签。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星