UILabel UITextField常用方法总结

UILabel : UIView <NSCoding>

1.创建一个UILabel对象

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(303028060)];

 

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,10028030)];

 

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

        

        return NO;

    }

    NSLog(@"%@",string);

    return YES;

 

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

//返回按钮调用方法

posted on 2015-12-16 20:54  窗外美景  阅读(76)  评论(0)    收藏  举报