美文网首页
UIButton图文位置设置EdgeInsets

UIButton图文位置设置EdgeInsets

作者: 然亦伞 | 来源:发表于2016-08-03 16:04 被阅读36次

    1、 图片在文字右边

    CGFloat titleW = showSelectClickBtn.titleLabel.width;

    CGFloat imgW = showSelectClickBtn.imageView.width ;

    [showSelectClickBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -imgW, 0, imgW)];

    [showSelectClickBtn setImageEdgeInsets:UIEdgeInsetsMake(0, titleW, 0, -titleW)];

    2、图片在文字上面

    showSelectClickBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    CGFloat imgHlafW = showSelectClickBtn.imageView.width * 0.5;

    CGFloat imgHlafH = showSelectClickBtn.imageView.height * 0.5;

    CGFloat titleHlafW = showSelectClickBtn.titleLabel.width * 0.5;

    CGFloat titleHlafH = showSelectClickBtn.titleLabel.height * 0.5;

    [showSelectClickBtn setTitleEdgeInsets:UIEdgeInsetsMake(imgHlafH,-imgHlafW, -imgHlafH, imgHlafW)];

    [showSelectClickBtn setImageEdgeInsets:UIEdgeInsetsMake(-titleHlafH,titleHlafW,titleHlafH, -titleHlafW)];

    相关文章

      网友评论

          本文标题:UIButton图文位置设置EdgeInsets

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