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确定后调用
网友评论