使用XIB自定义UIButton

时间:2012-10-07 14:47:45

标签: iphone ios uibutton custom-controls

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

非常感谢

1 个答案:

答案 0 :(得分:1)

像这样实现UIButton:

@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
使用XIB文件的UIView也可以在这个类中添加一个子视图,你知道这意味着什么:)