我该如何更改UIButton上文本的颜色。这是我的当前代码:
UIButton *b1 = [[UIButton alloc] init];
b1.frame = CGRectMake(280,395,30,30);
[[b1 layer] setCornerRadius:8.0f];
[[b1 layer] setMasksToBounds:YES];
[[b1 layer] setBorderWidth:1.0f];
[[b1 layer] setBackgroundColor:[botCol CGColor]];
b1.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[b1 setTitleColor:[UIColor redColor] forState:UIControlEventAllEvents];
[b1 addTarget:self action:@selector(NextButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[b1 setTitle:@">" forState:UIControlStateNormal];
[self.view addSubview:b1];
这是它的外观(忽略背景颜色和其他东西):
现在,我该如何让箭头变成红色?如上所述,我已经有了以下内容:
[b1 setTitleColor:[UIColor redColor] forState:UIControlEventAllEvents];
但它没有起作用。
[[b1 layer] setBackgroundColor:[UIColor greenColor].CGColor];
但是,你必须将b1
变成实例变量才能在原始方法之外访问它。 - sudo rm -rf