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

来源:互联网 发布:淘宝店设置低于7折 编辑:程序博客网 时间:2024/06/05 20:22

UILabel :UIView <NSCoding>

1.创建一个UILabel对象

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


2.backgroundColor

背景颜色


3.text

显示的文本信息

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


4.textColor

文本颜色

eg:label.textColor = [UIColoryellowColor];


5.shadowColor

文本阴影颜色

eg:label.shadowColor = [UIColorblueColor];


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 = [UIFontsystemFontOfSize: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

清除按钮

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 ([stringisEqualToString:@"a"]) {

        

        returnNO;

    }

    NSLog(@"%@",string);

    returnYES;


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

//返回按钮调用方法

1 0