uitextfield 属性

参考文章地址:http://my.oschina.net/plumsoft/blog/42310

Attribute Inspector 分为三部分,分别是 Text Field、Control 和 View 部分。我们重点看看 Text Field 部分。

Text Field 部分有以下选项:

1、Text :设置文本框的默认文本。

2、Placeholder : 可以在文本框中显示灰色的字,用于提示用户应该在这个文本框输入什么内容。当这个文本框中输入了数据时,用于提示的灰色的字将会自动消失。

3、Background :可以设置背景颜色或者时以背景图片用为背景颜色

4、Disabled : 若选中此项,用户将不能更改文本框内容。

5、接下来是三个按钮,用来设置对齐方式。

6、Border Style : 选择边界风格。

typedef NS_ENUM(NSInteger, UITextBorderStyle) {

    UITextBorderStyleNone,//none空白 默认

    UITextBorderStyleLine,//黑色的边深色的底色

    UITextBorderStyleBezel,//与上面不同的只是颜色

    UITextBorderStyleRoundedRect//圆角的

};

7、clearButton: 你可以选择清除按钮什么时候出现,所谓清除按钮就是出一个现在文本框右边的小 X ,你可以有以下选择:

typedef NS_ENUM(NSInteger, UITextFieldViewMode) {

    UITextFieldViewModeNever,//从不出现 默认

    UITextFieldViewModeWhileEditing,//当编辑时出现删除按钮

    UITextFieldViewModeUnlessEditing,//删除按钮在编辑时消失

    UITextFieldViewModeAlways//一直在

};


8、 clearsOnBeginEditing: BOOL值类型, 若为YES,则当开始编辑这个文本框时,文本框中之前的内容会被清除掉,默认是NO。

9、Text Color : 设置文本框中文本的颜色。

10、Font : 设置文本的字体与字号。

11、minimumFontSize: 设置文本框可以显示的最小字体(一般配合下面自动调整使用)

12、adjustsFontSizeToFitWidth: 指定当文本框尺寸减小时,文本框中的文本是否也要缩小。选择它,可以使得全部文本都可见,即使文本很长。但是这个选项要跟 minimumFontSize 配合使用,文本再缩小,也不会小于设定的 minimumFontSize 

接下来的部分用于设置键盘如何显示。

13、autocapitalizationType : 设置大写。下拉菜单中有四个选项:   

typedef NS_ENUM(NSInteger, UITextAutocapitalizationType) {

    UITextAutocapitalizationTypeNone,//小写 默认

    UITextAutocapitalizationTypeWords,//每个单词首字母大写、单词以空格区分开

    UITextAutocapitalizationTypeSentences,//首字母大写

    UITextAutocapitalizationTypeAllCharacters,//全部大写

};

14、autocorrectionType : 检查拼写,默认是 YES 。

typedef NS_ENUM(NSInteger, UITextAutocorrectionType) {

    UITextAutocorrectionTypeDefault,检查拼写和YES一样

    UITextAutocorrectionTypeNo,不检查拼写

    UITextAutocorrectionTypeYes,检查拼写,默认

};

15、keyboardType : 选择键盘类型,比如全数字、字母和数字等。

typedef NS_ENUM(NSInteger, UIKeyboardType) {

    UIKeyboardTypeDefault,                // Default type for the current input method.

    UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active

    UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.

    UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).

    UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.

    UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).

    UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.

    UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).

#if __IPHONE_4_1 <= __IPHONE_OS_VERSION_MAX_ALLOWED

    UIKeyboardTypeDecimalPad,             // A number pad with a decimal point.

#endif

#if __IPHONE_5_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED

    UIKeyboardTypeTwitter,                // A type optimized for twitter text entry (easy access to @ #)

#endif


    UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated


};

16、keyboardAppearance:键盘的配色。默认的时浅蓝色,UIKeyboardAppearanceAlert时是棕色

17、returnKeyType: 选择返回键(虚拟键盘右下角的文字显示),可以选择 Search 、 Return 、 Done 等。

typedef NS_ENUM(NSInteger, UIReturnKeyType) {

    UIReturnKeyDefault,

    UIReturnKeyGo,

    UIReturnKeyGoogle,

    UIReturnKeyJoin,

    UIReturnKeyNext,

    UIReturnKeyRoute,

    UIReturnKeySearch,

    UIReturnKeySend,

    UIReturnKeyYahoo,

    UIReturnKeyDone,

    UIReturnKeyEmergencyCall,

};


18、 enablesReturnKeyAutomatically:BOOL值类型 如选择此项为YES,则只有至少在文本框输入一个字符后键盘的返回键才有效。默认为NO,一般没特别需求不要修改,不知道情况的感觉体验不好。

19、secureTextEntry : 当你的文本框用作密码输入框时,可以选择这个选项,此时,字符显示为星号。

/

.h文件:

#import <UIKit/UIKit.h>

@interface textfieldViewController : UIViewController<UITextFieldDelegate>

@end

.m文件:

_field.delegate=self;//设置代理实现下面的事件

-(BOOL) textFieldShouldReturn:(UITextField *)textField//在按虚拟键盘右下角的done按钮时执行的时间
{
    NSLog(@"%@",textField.text);
    [textField resignFirstResponder];//textfield失去焦点使键盘隐藏
    return YES;//YES和NO都试了下。发现居然没区别。不知道那位知道这有什么区别
}


代理的另外一些事件:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.

- (void)textFieldDidBeginEditing:(UITextField *)textField;           // became first responder

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;          // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end

- (void)textFieldDidEndEditing:(UITextField *)textField;             // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // return NO to not change text


- (BOOL)textFieldShouldClear:(UITextField *)textField;               // called when clear button pressed. return NO to ignore (no notifications)

- (BOOL)textFieldShouldReturn:(UITextField *)textField;              // called when 'return' key pressed. return NO to ignore.






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值