UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
这个一直搞不太懂,看文档也没看太明白,网上看了好多资料也都不是太满意 ,今天自己着重研究了下
UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 200, 200)];
[button setTitle:@"我是按钮" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"refresh_02a.png"] forState:UIControlStateNormal];
button.backgroundColor = [UIColor yellowColor];
NSLog(@"%@,%@",button.titleLabel,button.imageView);
button.titleEdgeInsets = UIEdgeInsetsMake(29, -22, -29, 22);
button.imageEdgeInsets = UIEdgeInsetsMake(-15, 36, 15, -36);
NSLog(@"%@,%@",button.titleLabel,button.imageView);
[self.view addSubview:button];
这个是原码
UIEdgeInsetsMake(给上部分加的距离>, <给左部分加的距离>, <给下部分加的距离>, <给右部分加的距离)
正数就是加负数就是减
因为image和lable的宽高是不能变的 所以最好一边加了相对方向就减相同的数