标签:
自定义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); }
标签:
原文地址:http://www.cnblogs.com/sixindev/p/4468627.html