2013-08-24 44 views
1

到目前为止,我已经改变了所有这一切都在我的类使用下面的代码设置类的cornerRadius使用的UIButton appearanceWhenContainedIn

[[UIButton appearanceWhenContainedIn:[FirstPadViewController class], nil] setBackgroundImage:img forState:UIControlStateNormal]; 

因为我不希望创建就是为什么我使用了一个出口的按钮图像这条路。所以,我怎么可以设置cornerRadius使用的UIButton appearanceWhenContainedIn

我试过,但它不工作

[[[UIButton appearanceWhenContainedIn:[FirstPadViewController class], nil] layer ] setCornerRadius:20]; 
[[[UIButton appearanceWhenContainedIn:[FirstPadViewController class], nil] layer ] setMasksToBounds:YES]; 

回答

2

基本上,你不能这样做。而且,即使它有效,任何时候都可以随时更新,或者具有未定义的行为。

UIAppearance代理保留给声明UI_APPEARANCE_SELECTOR的方法/属性。

看看this list看看你可以用UIAppearance来定制什么。据它,你可以只更改tintColor。该列表尚未完成,但layer(和扩展名,cornerRadius)不在外观选择器中。

+0

我想上面的代码,但它不工作,你确定它不可能动原因男人这样可以真的节省了我很多时间 – java

+1

好吧,如果我理解了这个问题,并且你想用'UIAppearance'在所有'UIButton'上应用'setCornerRadius',我认为这是不可能的。我可能是错的,但在任何地方都没有看到。 – DCMaxxx

+0

是的,我认为你是对的,我试过了,没有任何事情发生 – java

-2

写这段代码在你的班上,it'l工作,但我不知道是不是对你合适

for(UIView *view in self.view.subviews) 
     if([view isKindOfClass:[UIButton class]]){ 
      UIButton *btn= (UIButton *)view; 
      btn.layer.cornerRadius = 5; 
      btn.layer.borderColor = [UIColor redColor].CGColor; 
      btn.layer.borderWidth =5; 

     }