美文网首页
UIButton图标与文字间距设置

UIButton图标与文字间距设置

作者: RunningMan_Fly | 来源:发表于2016-04-21 18:23 被阅读5270次

    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>

    相关文章

      网友评论

          本文标题:UIButton图标与文字间距设置

          本文链接:https://www.haomeiwen.com/subject/grftrttx.html