【发布时间】:2015-04-23 20:42:36
【问题描述】:
我正在以编程方式生成我的自定义视图控制器的视图,包括添加一些按钮。我连续三个按钮,都是按照这个顺序创建的:
self.futureButton = [[UIButton alloc] initWithFrame:CGRectMake(0, buttonOffset, _width/3, _height*.1)];
self.futureButton.backgroundColor = [UIColor pinkColor];
self.futureButton.tag = 1;
[self.futureButton setTitle:@"Upcoming" forState: UIControlStateNormal];
[self.futureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[self setColor:[UIColor lightPinkColor] forState:UIControlStateSelected forButton:self.futureButton];
[self.futureButton addTarget:self action:@selector(changAppt:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.futureButton];
我最后也会这样做,以将相同的属性应用于所有这些按钮:
for(UIButton *myButton in self.view.subviews){
if([myButton isKindOfClass:[UIButton class]]){
[[myButton layer] setBorderWidth:4.0f];
[[myButton layer] setBorderColor:[UIColor whiteColor].CGColor];
[myButton.layer setCornerRadius:12.0f];<----problem
}
}
除了最后一个命令 setCornerRadius 之外,一切都运行良好。如果我把它注释掉,我就会得到我想要的——所有按钮都排成一行,白色边框消失在背景白色中。但是,如果我使用最后一个命令 setCornerRadius,我会得到以下信息(见图)
此外,无论选择哪个按钮,都会产生奇怪的效果。我必须对选定的状态效果和 CornerRadius 做些什么吗?如果有,是什么?
【问题讨论】:
-
我的回答解决了问题吗?期待您的回复
标签: objective-c uibutton