Uitextfield Usage Details

Source: Internet
Author: User

Uitextfield Usage Details

This blog is a summary of my use of uitextfield. It does not have much nutrition and will be updated continuously.

2014.9.15

Certificate --------------------------------------------------------------------------------------------------------------------------------------

Source code:

//// Rootviewcontroller. M // uitextfield // created by youxianming on 14-9-15. // copyright (c) 2014 youxianming. all rights reserved. // # import "rootviewcontroller. H "@ interface rootviewcontroller () <uitextfielddelegate> @ property (nonatomic, strong) uitextfield * textfield; @ end @ implementation rootviewcontroller-(void) viewdidload {[Super viewdidload]; _ textfield = [[uitextfield alloc] initwithframe: cgrectmake (10, 80,300, 40)]; _ textfield. layer. borderwidth = 1.f; _ textfield. layer. bordercolor = [uicolor redcolor]. cgcolor; _ textfield. backgroundcolor = [uicolor whitecolor]; _ textfield. textalignment = kcttextalignmentleft; // left-aligned _ textfield. delegate = self; _ textfield. keyboardtype = uikeyboardtypenumberpad; // keypad _ textfield. placeholder = @ "enter a four-digit verification code"; _ textfield. clearsonbeginediting = yes; // Empty left edge space (implemented by adding a view) uiview * view = [[uiview alloc] initwithframe: cgrectmake (0, 0, 10, cgrectgetheight (_ textfield. bounds)]; _ textfield. leftview = view; _ textfield. leftviewmode = uitextfieldviewmodealways; [self. view addsubview: _ textfield]; // Add gesture [self addgesture];}-(void) addgesture {// gesture ** tap = [[uitapgesturerecognizer alloc] initwithtarget: Self action: @ selector (tapgesture :)]; [self. view addgesturerecognizer: tap];} // restrict the input length-(bool) textfield :( uitextfield *) textfield shouldchangecharactersinrange :( nsange) range replacementstring :( nsstring *) string {If (range. location >=4) {return no;} else {return yes;}-(void) tapgesture :( uitapgesturerecognizer *) tap {// cancel the first response status [_ textfield resignfirstresponder];} @ end

Effect:

Left blank gap

Limit input length

Certificate --------------------------------------------------------------------------------------------------------------------------------------

 

Uitextfield Usage Details

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.