张洋给的自定义UIButton的title和image位置的方法:
1.继承自UIButton
2.重写这两个方法:
-(CGRect)titleRectForContentRect:(CGRect)contentRect { CGFloat titleY = contentRect.size.height *0.6; CGFloat titleW = contentRect.size.width; CGFloat titleH = contentRect.size.height - titleY; return CGRectMake(0, titleY, titleW, titleH); }
-(CGRect)imageRectForContentRect:(CGRect)contentRect { CGFloat imageW = CGRectGetWidth(contentRect); CGFloat imageH = contentRect.size.height * 0.6; return CGRectMake(0, 0, imageW, imageH); } |