相关疑难解决方法(0)

以编程方式设置UIButton的buttonType

我有一个UIButton我在IB中添加的,但是这个按钮后面的视图会改变颜色,我需要在InfoDarkInfoLight之间切换按钮的类型.但奇怪的是,buttonType财产是只读的.那么如何在明暗信息按钮之间切换?

iphone objective-c uibutton programmatically-created

23
推荐指数
2
解决办法
4万
查看次数

如何在UIButton子类中设置UIButton类型

我是UIButton的子类,我想要的是将按钮类型设置为Round Rect.

Button.h

@interface Button : UIButton {}
    - (void)initialize;
@end
Run Code Online (Sandbox Code Playgroud)

Button.m

@implementation Button

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}


-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if(self){
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    self.titleLabel.textColor = [UIColor redColor];
    self.titleLabel.textAlignment = UITextAlignmentCenter;
   //[UIButton buttonWithType:UIButtonTypeRoundedRect];
}

@end
Run Code Online (Sandbox Code Playgroud)

在这里我尝试[UIButton buttonWithType:UIButtonTypeRoundedRect]但它不起作用.任何人都可以建议如何使其工作?

我在之前的许多文章中都知道,不推荐使用Subclassing UIButton,但事实上在Developer's Docs中没有提及NOT子类化它.

subclass uibutton ios

16
推荐指数
4
解决办法
2万
查看次数

以编程方式更改UIButton类型

我有一个用IB制作的UIButton,它设置为"Rounded Rect".有一次,我想在代码中将类型更改为"自定义",这可能吗?我看到类型可以在创建时设置,但是没有看到以后是否可以更改它.

cocoa-touch objective-c uibutton

6
推荐指数
1
解决办法
1万
查看次数