苹果开发 笔记(60)文本字体、大小 、颜色、边框 设置

IOS 7 之后TextKit的出现, IOS文字渲染机制发生改变。前端经常要和文字打交道,现在看看需要我们常常做的。下面记录一下平时常见的操作作一个笔记。

UILabel
UIButton
UITextField

1. UILabel

1.1 设置label的文本大小

 UILabel *label = [[UILabel alloc]init];
 label.font = [UIFont systemFontOfSize:18];


1.2 设置label的文本颜色

UILabel *label = [[UILabel alloc]init];
label.textColor =  [UIColor redColor];


1.3 去掉label的背景色

UILabel *label = [[UILabel alloc]init];
label.backgroundColor = [UIColor clearColor];


1.4 设置label的背景色

UILabel *label = [[UILabel alloc]init];
label.backgroundColor = [UIColor redColor];
<br>

1.5 设置label 的边框

UILabel *label = [[UILabel alloc]init];
label.layer.borderColor = [UIColor colorWithRed:215.0/255.0 green:215.0/255.0 blue:215.0/255.0 alpha:1].CGColor;
label.layer.borderWidth = 0.6f;
label.layer.cornerRadius = 6.0f;


1.6 设置label 的字体

UILabel *label = [[UILabel alloc]init];
label.font = [UIFont fontWithName:@"Helvetica" size:18];


2. UIButton

2.1 设置按钮标题的文本大小

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font =[UIFont systemFontOfSize:18];


2.2 设置按钮标题的文本颜色

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
 [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
 [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];


2.3 去掉背景色

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor clearColor];


2.4 设置按钮的背景色

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor greenColor];
<br>

2.5 设置按钮文本的字体

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font =[UIFont fontWithName:@"Helvetica" size:18];


3. UITextField

3.1 设置文本大小

 UITextField *textField = [[UITextField alloc]init];
 textField.font  = [UIFont systemFontOfSize:18];


3.2 设置文本的颜色

UITextField *textField = [[UITextField alloc]init];
textField.textColor = [UIColor redColor];


3.3 去掉文本的背景色

UITextField *textField = [[UITextField alloc]init];
textField.backgroundColor = [UIColor clearColor];


3.4 设置文本的背景色

UITextField *textField = [[UITextField alloc]init];
textField.backgroundColor = [UIColor grayColor];


3.5 设置文本的边框

UITextField *textField = [[UITextField alloc]init];
UITextField.layer.borderColor = [UIColor colorWithRed:215.0/255.0 green:215.0/255.0 blue:215.0/255.0 alpha:1].CGColor;
UITextField.layer.borderWidth = 0.6f;
UITextField.layer.cornerRadius = 6.0f;


3.6 设置文本的字体

UITextField *textField = [[UITextField alloc]init];
textField.font =[UIFont fontWithName:@"Helvetica" size:18];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值