UIButton 设置image ,title和setBackgroundImage
2015-10-23 00:01
495 查看
定制一个image 和title 有一定距离的UIButton
UIButton的
就是如果你设置的是backgroundImage 而不是image的话,那么如果这个图片过小的话这个图片是会被拉伸的。
// the space between the image and text CGFloat spacing = 6.0; // lower the text and push it left so it appears centered // below the image CGSize imageSize = button.imageView.image.size; button.titleEdgeInsets = UIEdgeInsetsMake( 0.0, - imageSize.width, - (imageSize.height + spacing), 0.0); // raise the image and push it right so it appears centered // above the text CGSize titleSize = [button.titleLabel.text sizeWithAttributes:@{NSFontAttributeName: button.titleLabel.font}]; button.imageEdgeInsets = UIEdgeInsetsMake( - (titleSize.height + spacing), 0.0, 0.0, - titleSize.width);
UIButton的
setBackgroundImage是设置背景图片,而
setImage则是设置一个挨着title的一个icon 或者image。
就是如果你设置的是backgroundImage 而不是image的话,那么如果这个图片过小的话这个图片是会被拉伸的。
相关文章推荐
- ERPbuilder:连锁零售企业发展的新思路
- 从信息走向交易,B2Bbuilder能做些什么
- ERPbuilder:连锁零售企业发展的新思路
- Chapter 0.SymmetricDS快速入门指南( Quick Start Guide)
- web 应用 使用 shiro 安全框架 在 was7访问性能慢
- 详细整理:UITableView优化技巧
- vector容器 std::unique函数的实现
- UVA1621 Guess(贪心+精度)
- UITabBarController定制
- 最长公共上升子序列——hdu1423 Greatest Common Increasing Subsequence
- IOS 开发UI篇—iOS开发中三种简单的动画设置
- 关于java ArrayBlockingQueue 源码解析的小疑惑
- 关于UINavigationContrller官方文档翻译
- uestc 594 我要长高 单调队列优化
- (面试题)两个对象值相同 (x.equals(y) == true) ,但却可有不同的 hash code ,这 句话对不对?
- android入门(一)---UI组件之文本框(TextView)
- 蓝牙Android_Lightblue调试工具存在的bug
- 基于STM32与μC/GUI的多路PID控制器
- Servlet的生命周期及filter,servletRequest和servletResponse
- 在Android6.0中使用AlertDialog.Builder出现的问题