UIImage *img = [UIImage imageNamed:@"hoVV"];
[_categoryBtn setImage:img forState:UIControlStateNormal];
_categoryBtn.backgroundColor = [UIColor greenColor];
CGRect rect = [_categoryBtn.titleLabel.text boundingRectWithSize:CGSizeMake(100000, 50) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[FGLiveTools getFontWithType:FGBook size:60]} context:nil];
[_categoryBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -img.size.width, 0, img.size.width)];
[_categoryBtn setImageEdgeInsets:UIEdgeInsetsMake(0,rect.size.width+20, 0, -rect.size.width)];
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height ,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
[btn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,0.0, -btn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
网友评论