自定义按钮之:文字图片位置随意定制http://www.tuicool.com/articles/YvUJnqR
左title右image
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectZero];
[btn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
btn.backgroundColor = [UIColor yellowColor];
[btn setTitle:@"冰与火的世界" forState:(UIControlStateNormal)];
[btn setImage:[UIImage imageNamed:@"aa"] forState:(UIControlStateNormal)];
// top : 为正数的时候,是往下偏移,为负数的时候往上偏移;
// left : 为正数的时候往右偏移,为负数的时候往左偏移;
// bottom : 为正数的时候往上偏移,为负数的时候往下偏移;
// right :为正数的时候往左偏移,为负数的时候往右偏移;
// 上左下右 正里负外
// 移动是一起运动的 成对的(0, 60, 0, -60)
btn.titleLabel.backgroundColor = [UIColor redColor];
NSLog(@"%f",btn.titleLabel.intrinsicContentSize.width);
NSLog(@"%f",btn.currentImage.size.width);
CGFloat labW = btn.titleLabel.intrinsicContentSize.width;
CGFloat imgW = btn.currentImage.size.width;
CGFloat space = 1;
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, labW + space, 0, -labW - space)];
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -imgW - space, 0, imgW + space)];
btn.frame = CGRectMake(100, 100, labW + imgW + 2*space, 50);
[self.view addSubview:btn];