ios开发怎么设置button的背景色
答案:1 悬赏:50 手机版
解决时间 2021-04-04 13:32
- 提问者网友:杀手的诗
- 2021-04-04 09:02
ios开发怎么设置button的背景色
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-04-04 10:19
1.通过按钮的事件来设置背景色
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 100, 50)];
[button1 setTitle:@"button1" forState:UIControlStateNormal];
button1.backgroundColor = [UIColor orangeColor];
[button1 addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
[button1 addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
// button1普通状态下的背景色
- (void)button1BackGroundNormal:(UIButton *)sender
{
sender.backgroundColor = [UIColor orangeColor];
}
// button1高亮状态下的背景色
- (void)button1BackGroundHighlighted:(UIButton *)sender
{
sender.backgroundColor = [UIColor greenColor];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 100, 50)];
[button1 setTitle:@"button1" forState:UIControlStateNormal];
button1.backgroundColor = [UIColor orangeColor];
[button1 addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
[button1 addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
// button1普通状态下的背景色
- (void)button1BackGroundNormal:(UIButton *)sender
{
sender.backgroundColor = [UIColor orangeColor];
}
// button1高亮状态下的背景色
- (void)button1BackGroundHighlighted:(UIButton *)sender
{
sender.backgroundColor = [UIColor greenColor];
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯