UIButton的文字显示位置、字体的大小、字体的颜色
2015-12-11 10:49
405 查看
btn.frame = CGRectMake(x, y, width, height);
[btn setTitle: @"search" forState: UIControlStateNormal];
//设置按钮上的自体的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法
//应该使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btn seBackgroundColor: [UIColor blueColor]];
//最后将按钮加入到指定视图superView
[superView addSubview: btn];
==========================================================
tvnamelabel=[[UIButton alloc]initWithFrame:CGRectMake(5,5,200,40)];
这样初始化的button,文字默认颜色是白色的,所有如果背景也是白色的话,是看不到文字的,
btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置,现设为居左,默认的是居中
[btn setTitle:@“title”forState:UIControlStateNormal];// 添加文字
有些时候我们想让UIButton的title居左对齐,我们设置
btn.textLabel.textAlignment = UITextAlignmentLeft
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; //偏移{top, left, bottom,
right};
按钮中title的偏移
=======================================================
设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
[btn setTitle: @"search" forState: UIControlStateNormal];
//设置按钮上的自体的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法
//应该使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btn seBackgroundColor: [UIColor blueColor]];
//最后将按钮加入到指定视图superView
[superView addSubview: btn];
==========================================================
tvnamelabel=[[UIButton alloc]initWithFrame:CGRectMake(5,5,200,40)];
这样初始化的button,文字默认颜色是白色的,所有如果背景也是白色的话,是看不到文字的,
btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置,现设为居左,默认的是居中
[btn setTitle:@“title”forState:UIControlStateNormal];// 添加文字
有些时候我们想让UIButton的title居左对齐,我们设置
btn.textLabel.textAlignment = UITextAlignmentLeft
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; //偏移{top, left, bottom,
right};
按钮中title的偏移
=======================================================
设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
相关文章推荐
- iOS--- UISegment属性
- iOS开发 UIAlertController的创建与使用
- 前端,移动开发者,UI须懂: 不同设备的之间的尺寸
- UITextField 键盘挡住输入框 输入内容限制 设定
- UITextField判断用户输入是否为邮箱
- How to deal with the error message "Could not load SAPGUIResources"
- iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?
- 前端,移动开发者,UI须懂: 不同设备的之间的尺寸
- LeetCode 232 Implement Queue using Stacks
- SSH自动生成主键+UUID生成主键
- Java中String、StringBuffer、StringBuilder和toString的介绍
- leetcode:232 Implement Queue using Stacks-每日编程第十六题
- UIButton 使用注意事项
- sui-mobile框架入门一
- ServletFileUpload、MultipartRequest与MultipartParser的区别
- UICollectionView
- LeetCode 225 Implement Stack using Queues
- ListView下拉刷新控件详解
- 集合视图 UICollectionView
- UIPageControl 页码控制器