4

我知道可以使用 XIB 文件制作自定义 UITableViewCell 并执行此操作,但是我如何使用 Button 执行此操作,所以制作新的 Lables 或其他东西?

非常感谢

4

1 回答 1

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 也可以作为子视图添加到这个类中,你知道什么意思:)

于 2012-10-07T16:14:50.900 回答