Summary of common methods for Uitextfield iOS base controls

Source: Internet
Author: User

文本控件(UITextField)继承了UIControl控件,所以作为活动控件使用!创建该控件有两种方法:一、拖控件。二、纯代码搞定。其实本质一样。不过还是建议采用纯代码,这样对控件的可定制性非常高。

Textfield=[[uitextfield Alloc]initwithframe:cgrectmake (120.0f, 80.0f, 150.0f, 30.0f)];
[TextField setborderstyle:uitextborderstyleroundedrect];//outer box type
[Email protected] "Please enter:";//words displayed by default
textfield.securetextentry=yes;//is a password-typed input box
textfield.clearbuttonmode=uitextfieldviewmodewhileediting;
textfield.delegate=self;
textfield.keyboardtype=uikeyboardtypedefault;//Keyboard Display Type
textfield.autocapitalizationtype=uitextautocorrectiontypeyes;//whether to turn on automatic alert correction function
textfield.contentverticalalignment=uicontrolcontentverticalalignmentcenter;//Center Display
typedef enum {
Uicontrolcontentverticalalignmentcenter = 0,
Uicontrolcontentverticalalignmenttop = 1,
Uicontrolcontentverticalalignmentbottom = 2,
Uicontrolcontentverticalalignmentfill = 3,
} uicontrolcontentverticalalignment;
Textfield.textcolor=[uicolor redcolor];//Font Color
Textfield.font=[uifont fontwithname:@ "Times New Roman" size:35];//font type and size
Textfield.background=[uiimage imagenamed:@ "background.png"];//background image

[self.view addSubview:textField];

Delegate method
-(void) textfielddidbeginediting: (Uitextfield *) TextField
{//The method is called when the text box is clicked
NSLog (@ "You start clicking on TextField! ”);
}
-(void) textfielddidendediting: (Uitextfield *) TextField
{//The method is called when the click is over
NSLog (@ "You end up clicking TextField! ”);}
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{//Click Return to close the keyboard
A common way to turn off the keyboard is to refer to another blog post
http://blog.csdn.net/it_ds/article/details/44830695
[TextField Resignfirstresponder];
return YES;
}
Limit the number of words entered in a text box
-(BOOL) TextField: (Uitextfield ) TextField shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString ) string
{
if (range.location>=max_length) {
return NO;

}return YES;}

Summary of common methods for Uitextfield iOS base controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.