继承自定义UIButton

时间:2012-01-20 22:11:30

标签: iphone objective-c ios

我正在尝试子类化自定义UIButton

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

我该怎么做?另外我该怎么做:

[self performSelectorOnMainThread:@selector(setBackgroundImage:forState:) withObject:image waitUntilDone:YES];

这可能吗?

1 个答案:

答案 0 :(得分:1)

只需编写自己的子类: MyCustomButton.h文件:

#import <Foundation/Foundation.h>

@interface MyCustomButton : UIButton
    // Declare custom properties, etc
@end

MyCustomButton.m文件:

#import "MyCustomButton.h"

@implementation MyCustomButton
   // @synthesize Custom Properties
   // Add in custom views, methods, etc
@end

然后在其他类中,将其称为MyCustomButton而不是UIButton

对于背景图像(或任何图像)的背景加载,请使用块。