美文网首页
Button图片文字一起显示

Button图片文字一起显示

作者: Hris | 来源:发表于2017-06-29 16:12 被阅读20次

//单纯的字体显示 设置字体的大小 [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

// 重拍、删除

for (int i=0; i<2; i++) {

UIButton *btn = [UIButton buttonWithType:0];

btn.frame = CGRectMake((CGRectGetWidth(_contentView.frame)/2+0.5)*i,

0,

CGRectGetWidth(_contentView.frame)/2-0.5, 38);

btn.backgroundColor = THEME_COLOR;

btn.tag = 100+i;

[_contentView addSubview:btn];

// icon (18,18)

CGFloat icon_w = (i==0? 19: 14);

CGFloat icon_H = (i==0? 16: 17);

btn.imageEdgeInsets = UIEdgeInsetsMake((CGRectGetHeight(btn.frame)-icon_H)/2,

55,

(CGRectGetHeight(btn.frame)-icon_H)/2,

CGRectGetWidth(btn.frame)-55-icon_w);

NSString *imageStr = (i==0? @"mine_video_reset": @"mine_video_delete");

[btn setImage:LOAD_IMAGE(imageStr) forState:UIControlStateNormal];

[btn setTitle:(i==0? @"重拍": @"删除") forState:UIControlStateNormal];

btn.titleLabel.font = [UIFont systemFontOfSize:15];

[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];

[btn addTarget:self action:@selector(playOrDelete:) forControlEvents:UIControlEventTouchUpInside];

}

效果图:

相关文章

网友评论

      本文标题:Button图片文字一起显示

      本文链接:https://www.haomeiwen.com/subject/qoamcxtx.html