苹果开发 笔记(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];

你可能感兴趣的:(苹果开发 笔记(60)文本字体、大小 、颜色、边框 设置)