UI 经常用法总结之--- UILabel UITextField (不断更新中)

时间:2023-03-09 05:55:10
UI 经常用法总结之--- UILabel UITextField (不断更新中)

UILabel :
UIView <NSCoding>

1.创建一个UILabel对象

UILabel *label = [[UILabel
alloc]initWithFrame:CGRectMake(30,
30, 280,
60)];

2.backgroundColor

背景颜色

3.text

显示的文本信息

eg:label.text =
@"显示的文本信息";

4.textColor

文本颜色

eg:label.textColor = [UIColor
yellowColor];

5.shadowColor

文本阴影颜色

eg:label.shadowColor = [UIColor
blueColor];

6.shadowOffset

文本阴影偏移量

eg:label.shadowOffset =
CGSizeMake(3, 3);

7.textAlignment

文本格式处理(对齐方式)

eg:label.textAlignment  =
NSTextAlignmentCenter;

8.lineBreakMode

当文本过长时, label显示的断行方式

eg:label.lineBreakMode =
NSLineBreakByTruncatingHead;

9.numberOfLines

控制label显示的行数

eg:label.numberOfLines =
0;

10.font

字体大小  系统默认字体大小17

eg:label.font = [UIFont
systemFontOfSize:20];

UITextField :
UIControl <UITextInput,
NSCoding>

1.创建一个UITextField对象

UITextField *name = [[UITextFieldalloc]initWithFrame:CGRectMake(30,100,
280, 30)];

2.placeholder

默认的占位字符串 一旦输入
自己主动隐藏

eg:name.placeholder =
@"请在这里输入";

3.secureTextEntry

输入转换为黑点

eg:name.secureTextEntry =
YES;

4.keyboardType

更改键盘类型

name.keyboardType =
UIKeyboardTypeASCIICapable;

5.borderStyle

外观控制

name.borderStyle =
UITextBorderStyleRoundedRect;

6.clearButtonMode

清除button

name.clearButtonMode =
UITextFieldViewModeWhileEditing;

7.backgroundColor

背景颜色

8.回收键盘操作

[textField resignFirstResponder];

9.- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;

//是否同意输入

10.- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString
*)string;

//限制输入字符

eg:   if ([string
isEqualToString:@"a"]) {

return
NO;

}

NSLog(@"%@",string);

return
YES;

11.- (BOOL)textFieldShouldReturn:(UITextField *)textField;

//返回button调用方法