UIButton的一些小应用

UIButton实现左文字右图片

[priceBtnsetTitleEdgeInsets: UIEdgeInsetsMake (0,  -priceBtn.imageView.size.width, 0, priceBtn.imageView.size.width)];

[priceBtnsetImageEdgeInsets: UIEdgeInsetsMake (0, priceBtn.titleLabel.bounds.size.width, 0, -priceBtn.titleLabel.bounds.size.width)];


UIButton实现上图下文字

CGSizeimageSize = collectBtn.imageView.frame.size;

CGSizetitleSize = collectBtn.titleLabel.frame.size;

// 图文间隔

CGFloatspacing = 5;

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

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

collectBtn.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, -(totalHeight - titleSize.height), 0.0);

你可能感兴趣的:(UIButton的一些小应用)