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