iOS 自定义UIButton的title和image位置
2016-05-09 16:43
549 查看
做项目需要,所以找了方法,与大家分享~ 亲测可用,contentRect就是我们给UIButton设置的frame值~
张洋给的自定义UIButton的title和image位置的方法:
1.继承自UIButton
2.重写这两个方法:
张洋给的自定义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); }
相关文章推荐
- 第十章 UINavigationController 翻译
- 数据库重构工具 LiquiBase(5 Liquibase被锁)
- Liquibase被锁
- 集合框架--Map集合values
- ArrayList的<STRING>到CharSequence的[]
- EqualsBuilder和HashCodeBuilder 作用
- iOS--UITableViewCell去除重影的方法
- Moqui学习之 Step by Step OrderProcureToPayBasicFlow
- 利用quic协议访问google
- UIView与CALayer
- 简单实现跑马灯效果
- 自己写的一个php基于phpQuery的通用采集类
- UIDatePicker转为汉字,并且显示年月日
- iOS自定义弹窗(UIView)
- ISO中根据URL下载图片,请求图片
- ui-router使用方法
- hdoj-5301-Buildings
- 347. Top K Frequent Elements【M】【VIP】【字典排序】
- 347. Top K Frequent Elements
- [BS-17] iOS开发-Alpha,Hidden和Opaque区别