user1710004
user1710004

Reputation: 209

Custom UIButton with XIB

I know that it is possible to make a custom UITableViewCell with a XIB file and did this, but how can I do this with a Button, so make new Lables or something?

Thank you very much

Upvotes: 4

Views: 2807

Answers (1)

uspython
uspython

Reputation: 563

Implement UIButton like this:

@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 which using an XIB file can also add in this class as a subview,you know what a mean:)

Upvotes: 1

Related Questions