自定义带图片和文字的Button的排版--陈棚
自定义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); }
作者:SIBU iOS DEV
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.