美文网首页
UIButton 图片居上文字居下

UIButton 图片居上文字居下

作者: 关羽007 | 来源:发表于2019-03-13 17:05 被阅读0次

    UIButton扩展一个方法:

    spacing 图片和文字的间隔

    - (void)verticalImageAndTitle:(CGFloat)spacing

    {

        CGSize imageSize = self.imageView.frame.size;

        CGSize titleSize = self.titleLabel.frame.size;

        CGSize textSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font];

        CGSizeframeSize =CGSizeMake(ceilf(textSize.width),ceilf(textSize.height));

        if(titleSize.width+0.5< frameSize.width) {

            titleSize.width= frameSize.width;

        }

        CGFloattotalHeight = (imageSize.height+ titleSize.height+ spacing);

        self.imageEdgeInsets=UIEdgeInsetsMake(- (totalHeight - imageSize.height),0.0,0.0, - titleSize.width);

        self.titleEdgeInsets=UIEdgeInsetsMake(0, - imageSize.width, - (totalHeight - titleSize.height),0);

    }

    相关文章

      网友评论

          本文标题:UIButton 图片居上文字居下

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