钟表,可以回到起点,却已不是错天

从零开始学习ios,(UITextFiled文本框)控件

基本控件----UITextFiled文本框

//

 UITextField *textname = [[UITextField alloc]

initWithFrame:CGRectMake(self.view.frame.size.width/5, 60.0, 40.0, 20.0)];

//设置边框类型、我的是圆角类型

[textname setBorderStyle:UITextBorderStyleRoundedRect];

typedef enum {

    UITextBorderStyleNone,无边框

    UITextBorderStyleLine,有边框,背景为透明

    UITextBorderStyleBezel,有边框和阴影,背景为透明

    UITextBorderStyleRoundedRect圆角,背景为白色

} UITextBorderStyle;

//设置提示文字,当写入文字时,提示内容会消失

     textname.placeholder = @"密码"

//设置文字的格式

[textnamesetFont:[UIFont fontWithName:@"Arial" size:10]];

NSLog(@"%@", [UIFont familyNames]);//查看字体集

//设置文字

textname.text = @”我是文本框”;

(也可以编辑之后获取文本框内容)

NSString * str = textname.text;

//密码格式的文字输入

textname.secureTextEntry = YES;

//设置文本内容部分的颜色

textname.backgroundColor = [UIColor blueColor];

//设置背景图片

textname.background=[UIImage imageNamed:@"图片名字"];

//设置键盘风格

textname.keyboardAppearance = UIKeyboardAppearanceDefault;

type enum{ 

UIKeyboardAppearanceDefault, 默认外观,浅灰色

UIKeyboardAppearanceAlert,     深灰 石墨色

}keyboardAppearance;

//设置键盘类型

  textname.keyboardType = UIKeyboardTypeNumberPad;//数字键

type enum{

UIKeyboardTypeDefault,          // 当前键盘(默认)

    UIKeyboardTypeASCIICapable,      // 字母输入键

    UIKeyboardTypeNumbersAndPunctuation,  //数字和符号

    UIKeyboardTypeURL,       //URL键盘

    UIKeyboardTypeNumberPad,  //数字键盘

    UIKeyboardTypePhonePad,   //电话号码输入键盘   

    UIKeyboardTypeEmailAddress, //邮件地址输入键盘          

} UIKeyboardType;

//设置弹出视图(不弹键盘弹图片),底部弹出视图

UIImageView * imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Icon.png"]];

 imageView.frame = CGRectMake(0, 100, 320, 100);(跟位置和宽无关)

textname.inputView = imageView;

//设置文本内左视图

   UIView * leftview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100   )];//只有宽度起到了作用

    textname.leftView = leftview;

    leftview.backgroundColor = [UIColor purpleColor];

//要设置左视图模式

 textname.leftViewMode = UITextFieldViewModeAlways;

(//还可以设置右视图

textname.rightView = rightView;

   textname.rightViewMode = UITextFieldViewModeAlways;、、这个右视图模式会影响清除按钮模式

)

//设置清楚按钮模式

 textname.clearButtonMode = UITextFieldViewModeAlways;//出现小叉子

typedef enum {

    UITextFieldViewModeNever,、、从不出现

    UITextFieldViewModeWhileEditing,编辑时显示

    UITextFieldViewModeUnlessEditing,不编辑时

    UITextFieldViewModeAlways  总是显示

} UITextFieldViewMode;

//设置再次编辑时是否清楚内容,默认为NO

textname.clearsOnBeginEditing = YES;

//编辑内容时垂直对齐方式,我是居中显示、默认是top显示对齐

textname.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

//文字内容居中显示

 textname.textAlignment = UITextAlignmentCenter;

//设置滚动

 textname.font = [UIFont systemFontOfSize:30];//可以设置文字大小

textname.adjustsFontSizeToFitWidth = YES;

//默认是NO  YES当充满边框时,文字会缩小,当小到一定程度时仍然会滚动;自适应宽度;

//设置滚动时最小字号(与滚动相关)(前提:要比设置的字体小,否则没有意义)

textname.minimumFontSize = 20;(没有设置这一项文字也会缩小和滚动)

//设置return键

textname.returnKeyType = UIReturnKeyGoogle;search

typedef enum {

    UIReturnKeyDefault, //默认 灰色按钮,标有Return

    UIReturnKeyGo,      //标有Go的蓝色按钮

    UIReturnKeyGoogle, //标有Google的蓝色按钮,用语搜索

    UIReturnKeyJoin,  //标有Join的蓝色按钮

    UIReturnKeyNext,  //标有Next的蓝色按钮

    UIReturnKeyRoute,  //标有Route的蓝色按钮

    UIReturnKeySearch,  //标有Search的蓝色按钮

    UIReturnKeySend,  //标有Send的蓝色按钮

    UIReturnKeyYahoo,  //标有Yahoo的蓝色按钮

    UIReturnKeyYahoo,    //标有Yahoo的蓝色按钮

    UIReturnKeyEmergencyCall,  //紧急呼叫按钮

} UIReturnKeyType;

//首字母是否大写

 textname.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;//所有字母大写

typedef enum {

    UITextAutocapitalizationTypeNone, 不自动大写

    UITextAutocapitalizationTypeWords,  单词首字母大写

    UITextAutocapitalizationTypeSentences,  句子的首字母大写

    UITextAutocapitalizationTypeAllCharacters, 所有字母都大写

} UITextAutocapitalizationType

 

[self.view addSubview: textname];

posted @ 2015-01-14 20:48  独一无二  阅读(484)  评论(0编辑  收藏  举报
世界上没有绝望得处境,只有对处境绝望得人