UIButton文字的显示位置,字体的大小
2015-11-23 14:30
369 查看
今天遇到个很简单的几个问题,关于UIButton的,以前没有很注意,就是设置它的文字的显示位置,字体的大小。
//设置按钮上的自体的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法
//应该使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
有些时候我们想让UIButton的title居左对齐,我们设置
btn.titleLabel.textAlignment = UITextAlignmentLeft;
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
//设置按钮上的自体的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法
//应该使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
有些时候我们想让UIButton的title居左对齐,我们设置
btn.titleLabel.textAlignment = UITextAlignmentLeft;
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
相关文章推荐
- Kibana User Guide [4.2] » Dashboard
- 从request中获取当前请求中的文件列表
- 将requirejs进行到底(一)
- 053-6 Which three statements about performance analysis by SQL Performance Analyzer are true?(Choose
- Easyui 验证验证扩展,限制combobox 只能输入选项内容
- ios蓝牙开发(四)BabyBluetooth蓝牙库
- Kibana User Guide [4.2] » Visualize » Vertical Bar Charts
- leetcode 304 : Range Sum Query 2D - Immutable
- arduino 串口数据啊按字节分析
- Xcode 7 UI 测试初窥
- String,StringBuffer,StringBuilder的区别
- A potentially dangerous Request.Form value was detected from the client
- 053-4 Which two statements about the SQL Management Base (SMB) are true? (Choose two.)
- UITableView上编辑UITextView
- QT的QSqlQuery与QSqlQueryModel RowCount只能读到256问题的解决
- 设置UIButton 字体 颜色
- request.getQueryString();
- String、StringBuffer、StringBuilder区别,HashMap与HashTable区别,final关键字详解及初始化成员变量位置,static关键字详解,抽象类与接口区别
- Gradle build设置自动log开关
- iOS 官方文档 UIGestureRecognizer