码迷,mamicode.com
首页 > 其他好文 > 详细

自定义带图片和文字的Button的排版

时间:2015-04-30 13:52:53      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

自定义button,动态加载图片与文字

 [footView addSubview:btnAllChoose];
    [btnAllChoose setTitle:str forState:UIControlStateNormal];
    [btnAllChoose setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
    btnAllChoose.titleLabel.font = [UIFont systemFontOfSize:10];
    [btnAllChoose setImage:[UIImage imageNamed:@"list_selected_icon"] forState:UIControlStateSelected];
    [btnAllChoose setImage:[UIImage imageNamed:@"list_give_icon"] forState:UIControlStateNormal];
    [btnAllChoose addTarget:self action:@selector(btnAllChooseAction:) forControlEvents:UIControlEventTouchUpInside];
    btnAllChoose.tag = 1001;

自定义UIbutton并继承Uibutton,修改button,内部方法

// 内部图片的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageW = contentRect.size.height;
    CGFloat imageH = contentRect.size.height ;
//    DLOG(@"imageH=%g",imageH);
    return CGRectMake(0, 0, imageW, imageH);
}

// 内部文字的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    
    CGFloat titleW = contentRect.size.width-contentRect.size.height-5;
    CGFloat titleH = contentRect.size.height;
    return CGRectMake(titleH+5, 0, titleW, titleH);
}

 

自定义带图片和文字的Button的排版

标签:

原文地址:http://www.cnblogs.com/sixindev/p/4468627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!