您的位置:首页 > 产品设计 > UI/UE

iOS 自定义UIButton的title和image位置

2016-05-09 16:43 549 查看
做项目需要,所以找了方法,与大家分享~ 亲测可用,contentRect就是我们给UIButton设置的frame值~

张洋给的自定义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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: