2012-01-20 171 views
0

我想继承自定义UIButton继承自定义的UIButton

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 

我该怎么办呢?我该怎么办:

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

这是可能的吗?

+0

试图子类或使用“UIButtonTypeCustom”? –

+0

你不应该继承'UIButton'。请参阅http://stackoverflow.com/questions/5045672/create-uibutton-subclass。 – smparkes

+0

嗯..试图创建一个类,lazily加载backgroundImage,那么我该怎么做呢? – adit

回答

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

为后台加载背景图片(或任何图片)使用块。