让UIButton在设计中更容易使用
修改UIButton的Image和title位置:
- - (void)flipHorizontalLayoutWithPadding:(float)padding
{
CGSize imageSize = self.imageView.frame.size;
CGSize titleSize = self.titleLabel.frame.size;
self.imageEdgeInsets = UIEdgeInsetsMake(0,
titleSize.width + padding/2.0,
0,
-(titleSize.width + padding/2.0));
self.titleEdgeInsets = UIEdgeInsetsMake(0,
-(imageSize.width + padding/2.0),
0,
imageSize.width + padding/2.0);
}
- (void)VerticalLayoutWithPadding:(float)padding
{
CGSize imageSize = self.imageView.frame.size;
CGSize titleSize = self.titleLabel.frame.size;
CGFloat totalHeight = (imageSize.height + titleSize.height + padding);
CGFloat totalWidth = (imageSize.width + titleSize.width - self.titleEdgeInsets.left - self.titleEdgeInsets.right);
self.titleEdgeInsets = UIEdgeInsetsMake(0.0f,
- imageSize.width,
- (totalHeight - titleSize.height),
0.0f);
self.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize.height),
(totalWidth - imageSize.width)/2.0 ,
0.0f,
- (totalWidth - imageSize.width)/2.0 );
}
@end