您的位置:首页 > 产品设计 > UI/UE

iPhone UIButton 图标与文字间距设置

2014-04-19 16:29 429 查看
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 150, 50)];

[button setTitle:@"HHH" forState:UIControlStateNormal];

[button setBackgroundImage:[UIImage imageNamed:@"narrowend.png"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"panelicon.png"] forState:UIControlStateNormal];

默认情况下,图片及按钮文字如下:



加入如下代码后

[button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -20, 0.0, 0.0)];



[button setImageEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#向上偏移量>, <#CGFloat left#向左偏移量>, <#CGFloat bottom#向下偏移量>, <#CGFloat right#向右上偏移量>)];

同时还可以设置文字的偏移量:

[button setTitleEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: