Nsarray *arraytext = @[@"User name",@"Password",@"Confirm Password",@"Phone number",@"Email"]; Nsarray*placeholders = @[@"Please enter user name",@"Please enter your password",@"Please confirm the password",@"Please enter your phone number",@"Please enter your email"]; Nsinteger y= -; for(inti =0; I <5; i++) {Ltview*aview = [[Ltview alloc] Initwithframe:cgrectmake ( -Y280, *)]; //Aview.backgroundcolor = [Uicolor redcolor];[Aview Setdeslabeltext:arraytext[i]]; [Aview Setplacehloder:placeholders[i]]; [Self.window Addsubview:aview]; [Aview setdelegate:self]; [Aview release]; if(i = =1|| i = =2) {[Aview setsecuretexttype:yes]; } if(i = =3) {[Aview setkeyboardtype:uikeyboardtypenumberpad]; } y+= $; } UIButton*BTN =[UIButton Buttonwithtype:uibuttontypesystem]; [BTN Settitle:@"Register"Forstate:uicontrolstatenormal]; Btn.frame= CGRectMake ( -, the, -, +); //Btn.backgroundcolor = [Uicolor redcolor];[view ADDSUBVIEW:BTN]; UIButton*BTN1 =[UIButton Buttonwithtype:uibuttontypesystem]; [Btn1 settitle:@"Cancel"Forstate:uicontrolstatenormal]; Btn1.frame= CGRectMake ( the, the, -, +); //Btn1.backgroundcolor = [Uicolor redcolor];[view ADDSUBVIEW:BTN1]; [Btn addtarget:self Action: @selector (Zhuce) forcontrolevents:uicontroleventtouchupinside]; [Btn1 addtarget:self Action: @selector (quit) forcontrolevents:uicontroleventtouchupinside]; Self.window.backgroundColor=[Uicolor Whitecolor]; [Self.window makekeyandvisible]; returnYES; }- (void) quit{//NSLog (@ "-----"); //UIView *view = [Self.window viewwithtag:50];//for (int i = 0; i < 5; i++) {//Uitextfield *fil = (Uitextfield *) [view Viewwithtag: (+ * i) + +];//Fil.text = @ "";// }[Self.window Endediting:yes]; }- (void) zhuce{//UIView *view = [Self.window viewwithtag:50];//for (int i = 0; i < 5; i++) {//Uitextfield *fil = (Uitextfield *) [view Viewwithtag: (+ * i) + +];//Fil.text = @ "=-==== top your lungs = =";// } }
LTView.h (custom UIView, defining interfaces)
@interface Ltview:uiview//Ltview is a custom view (combined view), carrying a label, TextField, two controls only Ltview can be identified by the dog, so ltview to the outside world to provide Operation label and TEXTFIEDLD access interface//an interface for setting text to a label- (void) Setdeslabeltext: (NSString *) text;//set hint text for TextField- (void) Setplacehloder: (NSString *) text;//Setting the keyboard interface for Txtfield- (void) Setkeyboardtype: (Uikeyboardtype) Keyboardtype;//to set the password format for TextField- (void) Setsecuretexttype: (BOOL) Securetexttype;-(NSString *) text;//to set the agent interface for TextField- (void) Setdelegate: (id<uitextfielddelegate>)Delegate; @end
LTVIEW.M (key in overriding initWithFrame method)
#import"LTView.h"@interface Ltview () @property (nonatomic,retain) UILabel*Deslabel, @property (nonatomic,retain) Uitextfield*TextField, @end @implementation Ltview/*Override the initWithFrame: Method inherited from the parent class to complete the creation of its own control when the custom view is initialized*/-(Instancetype) initWithFrame: (cgrect) frame{if(self =[Super Initwithframe:frame]) { //completing the creation of its own controls//label[Self setDescLabelWithWidth:frame.size.width/3Height:frame.size.height]; //TextField[Self setPlacehodlTextFieldWithWidth:frame.size.width/3*2Height:frame.size.height]; } returnSelf ;}//Create a label- (void) Setdesclabelwithwidth: (cgfloat) Width height: (cgfloat) height{Self.deslabel= [[UILabel alloc] Initwithframe:cgrectmake (0,0, width, height)]; //Self.desLabel.backgroundColor = [Uicolor redcolor];[self addSubview:self.desLabel]; [Self.deslabel release]; }//Create TextField- (void) Setplacehodltextfieldwithwidth: (cgfloat) Width height: (cgfloat) height{Self.textfield= [[Uitextfield alloc] initwithframe:cgrectmake (Width/2,0, width, height)]; Self.textField.borderStyle=Uitextborderstyleroundedrect; //Textfield.backgroundcolor = [Uicolor yellowcolor];[self AddSubview:self.textField]; [Self.textfield release];}//an interface for setting text to a label- (void) Setdeslabeltext: (NSString *) text{Self.desLabel.text=text;}//set hint text for TextField- (void) Setplacehloder: (NSString *) text{Self.textField.placeholder=text;}//Setting the keyboard interface for Txtfield- (void) Setkeyboardtype: (uikeyboardtype) keyboardtype{Self.textField.keyboardType=Keyboardtype;}//to set the password format for TextField- (void) Setsecuretexttype: (BOOL) securetexttype{self.textField.secureTextEntry=Securetexttype;}//get the text in TextField-(NSString *) text{returnSelf.textField.text;}//to set the agent interface for TextField- (void) Setdelegate: (id<uitextfielddelegate>)Delegate{Self.textfield.Delegate=Delegate; //The external parameters are who, who is the agent of this TextField}- (void) dealloc{[_deslabel release]; [_textfield release]; [Super Dealloc];} @end
Custom UIView in iOS (Get values in lable and textfile with interfaces)