美文网首页
UIButton设置图片在上文字在下

UIButton设置图片在上文字在下

作者: Desert_Eagle | 来源:发表于2018-06-13 11:04 被阅读0次
    UIButton *shareBtn = [_bottomView viewWithTag:1000+i];
     CGFloat spacing = -5;
      CGSize imageSize = shareBtn.imageView.frame.size;
       CGSize titleSize = shareBtn.titleLabel.frame.size;
        CGSize textSize = [shareBtn.titleLabel.text sizeWithFont:shareBtn.titleLabel.font];
      CGSize frameSize = CGSizeMake(ceilf(textSize.width), ceilf(textSize.height));
      if (titleSize.width + 0.5 < frameSize.width) {
          titleSize.width = frameSize.width;
        }
    
      CGFloat totalHeight = imageSize.height + titleSize.height;
       shareBtn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize.height + spacing), 0.0, 0.0, - titleSize.width);
      shareBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize.width, - (totalHeight - titleSize.height + spacing), 0);
    

    需button的frame确定后调用

    相关文章

      网友评论

          本文标题:UIButton设置图片在上文字在下

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