2012-10-07 188 views
4

我知道可以使用XIB文件制作自定义UITableViewCell并执行此操作,但是如何使用Button实现此操作,以便制作新的Lables或其他内容?自定义UIButton与XIB

非常感谢您

回答

1

实现的UIButton是这样的:它使用XIB文件,还可以添加在这个类作为一个子视图

@interface MyNewButton : UIButton{ 
    UILabel* nickNameLabel; 
    UIImageView* myImageView; 
} 

@property (nonatomic, retain) UIImageView *myImageView; 
@property (nonatomic, retain) UILabel* nickNameLabel; 
@end 

@implementation MyNewButton 
@synthesize myImageView; 
@synthesize nickNameLabel; 

- (id)initWithFrame:(CGRect)frame 
{ 
    myImageView=[[AXSImageView alloc] initWithFrame:CGRectMake(10, 3, 40, 40)]; 

    [self addSubview:myImageView]; 
    nickNameLabel=[[UILabel alloc] initWithFrame:CGRectMake(myImageView.frame.origin.x + myImageView.frame.size.width + 6, 15, 80, 17)]; 
    [self addSubview:nickNameLabel]; 
} 
- (void)drawRect:(CGRect)rect 
{ 
    //DO What You Need 
} 
- (void)dealloc 
{ 

    [nickNameLabel release],nickNameLabel=nil; 
    [myImageView release],myImageView=nil; 
    [super dealloc]; 
} 
@end 

UIView的,你知道什么是平均:)

+0

http://stackoverflow.com/questions/8014497/interface-builder-tutorial-on-how-to-customize-uibuttons-in-xcode-4-2 – Bala