1

到目前为止,我已经使用以下代码更改了班级中所有按钮的图像

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

因为我不想创建一个出口,这就是我使用这种方式的原因。那么如何使用 UIButton 设置cornerRadiusappearanceWhenContainedIn

我试过了,但它不起作用

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

2 回答 2

2

基本上,你不能那样做。而且,即使它有效,它也可能在任何时候因任何更新而中断,或者具有未定义的行为。

UIAppearance 代理保留给声明UI_APPEARANCE_SELECTOR.

看看这个列表,看看你可以用什么来定制UIAppearance。根据它,您只能更改tintColor. 该列表不完整,但layer(并且通过扩展,cornerRadius)不在外观选择器中。

于 2013-08-24T09:42:11.273 回答
-2

在你的课堂上写这段代码,它会工作,但我不知道你是否可以

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;

        }
于 2013-08-24T09:56:13.250 回答