UIButton的图文混排
来源:互联网 发布:中科大linux内核分析 编辑:程序博客网 时间:2024/05/21 13:22
我们常常需要用到按钮需要文字和图片同时显示,例如: 我们需要定义一个UIButton的子类实现文件- ( id )initWithFrame:( CGRect )frame{self = [ super initWithFrame :frame];if ( self ) { //可根据自己的需要随意调整 self . titleLabel . textAlignment = NSTextAlignmentRight ;self . titleLabel . font =[ UIFont systemFontOfSize : 14.0 ]; self . imageView . contentMode = UIViewContentModeLeft ;} return self ;}//重写父类UIButton的方法//更具button的rect设定并返回文本label的rect- ( CGRect )titleRectForContentRect:( CGRect )contentRect{CGFloat titleW = contentRect. size . width - 30 ;CGFloat titleH = contentRect. size . height ;CGFloat titleX = 0 ;CGFloat titleY = 0 ;contentRect = ( CGRect ){{titleX,titleY},{titleW,titleH}};return contentRect;}//更具button的rect设定并返回UIImageView的rect- ( CGRect )imageRectForContentRect:( CGRect )contentRect{CGFloat imageW = 25 ;CGFloat imageH = 25 ;CGFloat imageX = contentRect. size . width - 26 ;CGFloat imageY = 2.5 ;contentRect = ( CGRect ){{imageX,imageY},{imageW,imageH}};return contentRect;}//使用UIButton的子类yxpButton *selectAreaButton=[[ yxpButton alloc ] initWithFrame : CGRectMake ( 200 , 5 , 100 , 30 )]; [selectAreaButton setTitle : @"图文混排" forState : UIControlStateNormal ]; [selectAreaButton setImage :[ UIImage imageNamed : @"location" ] forState : UIControlStateNormal ]; [selectAreaButton setTitleColor :[ UIColor whiteColor ] forState : UIControlStateNormal ];[navigationBgView addSubview :selectAreaButton];就这样 就可以实现一个按钮的图文混排了
0 0
- UIButton的图文混排
- UIButton 的图文混排
- IOS总结_实现UIButton的图文混排(一)
- IOS总结_实现UIButton的图文混排(二)
- IOS总结_实现UIButton的图文混排(一)
- IOS总结_实现UIButton的图文混排(二)
- 关于UIButton的图文混排之图片
- IOS总结实现UIButton的图文混排 同时显示文字和图片
- 可视化编程 Tips 之“图文混排 UIButton 的可视化编辑”
- NGUI的图文混排
- 图文混排的数据处理
- Label 的图文混排
- TextView的图文混排,不同文字颜色混排
- 关于iphone图文混排的总结
- 一个简单的图文混排控件
- Android EditText图文混排的总结
- 一些 android 图文混排的资料
- FTCoreText图文混排框架的使用
- SID重复问题
- MyEclipse使用总结——MyEclipse文件查找技巧
- 使用邮件相关协议进行命令行收信与发信
- [leetcode] 140. Word Break II 解题报告
- JQuery获取浏览器窗口的可视区域高度和宽度,滚动条高度
- UIButton的图文混排
- iOS Info.plist
- 深度学习方向的牛人个人主页,文章必须带代码呀,持续更新
- C语言关键字解析(一)
- c# 换行符
- 欢迎使用CSDN-markdown编辑器
- OpenGL ES(2)——定义图形
- 交叉引用的解决方法-类方法的应用
- leetcode-Longest Increasing Subsequence