原文链接:http://www.jianshu.com/p/9c0dc91a3cf5
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
UIButton*button = [UIButtonbuttonWithType:UIButtonTypeCustom];
[buttonsetTitleEdgeInsets:insets];
[buttonsetFrame:CGRectMake(0,0,44,30)];
[buttonaddTarget:selfaction:actionforControlEvents:UIControlEventTouchUpInside];
[buttonsetTitle:textforState:UIControlStateNormal];
button.titleLabel.font= [UIFontsystemFontOfSize:14.0f];
[buttonsetTitleColor:[UIColorgrayColor]forState:UIControlStateNormal];
[buttonsetTitleColor:[UIColorhexStringToColor:@"808080"]forState:UIControlStateHighlighted];
[buttonsizeToFit];
[buttonsetFrame:CGRectMake(0,0, button.width+5,24)];
UIView*backBtnView = [[UIViewalloc]initWithFrame:button.bounds];
backBtnView.bounds=CGRectOffset(backBtnView.bounds,0,0);
[backBtnViewaddSubview:button];