使用XIB制作自定义UIButton

4

我知道可以使用XIB文件创建自定义的UITableViewCell,但是如何在按钮上实现类似的效果呢?比如添加新的标签等。

非常感谢

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


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接