Uiimageview:
1- (void) Viewdidload {2 [Super Viewdidload];3 4Uiimageview *imgview = [[Uiimageview alloc] Initwithframe:cgrectmake (ScreenWidth/2- $, the, the, -)];5Imgview.image = [UIImage imagenamed:@"logo"];6 [Self.view Addsubview:imgview];7 8}
Uitextfield:
- (void) viewdidload {[Super viewdidload]; Uitextfield*textfield = [[Uitextfield alloc] Initwithframe:cgrectmake ([UIScreen mainscreen].bounds.size.width/2- -, [UIScreen mainscreen].bounds.size.height/2- -, $, +)]; Textfield.placeholder=@"Please enter user name"; Textfield.textalignment= Nstextalignmentcenter;//Center//Image PathNSString *path = [[NSBundle mainbundle] Pathforresource:@"Login"OfType:@"PNG"]; //text field Add background imageTextfield.background =[UIImage Imagewithcontentsoffile:path]; [Self.view Addsubview:textfield]; }
Uitextfielddelegate protocol
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 5 @end6 7 @implementationViewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One AUitextfield *textfield = [[Uitextfield alloc] Initwithframe:cgrectmake ([UIScreen mainscreen].bounds.size.width/2- -, [UIScreen mainscreen].bounds.size.height- -, $, +)]; - -Textfield.placeholder =@"Please enter user name"; the -Textfield.textalignment = Nstextalignmentcenter;//Center - // //Image Path - //nsstring *path = [[NSBundle mainbundle] pathforresource:@ "login" oftype:@ "png"]; + // //text field Add background image - //textfield.background = [UIImage Imagewithcontentsoffile:path]; + A [Self.view Addsubview:textfield]; at -TextField.Delegate=Self ; - - } - --(BOOL) textfieldshouldbeginediting: (Uitextfield *) TextField//start editing as the whole moves upwards in { -[UIView animatewithduration:0.3Animations:^{self.view.frame = CGRectMake (self.view.frame.origin.x, SELF.VIEW.FRAME.ORIGIN.Y- -, Self.view.frame.size.width, self.view.frame.size.height);}]; to + returnYES; - } the * //-(void) textfielddidbeginediting: (Uitextfield *) TextField $ //{Panax Notoginseng // - //} the +-(BOOL) textfieldshouldendediting: (Uitextfield *) TextField A { the returnYES; + } -- (void) Textfielddidendediting: (Uitextfield *) TextField $ { $ - } --(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *)string the { -NSLog (@"%@",string);//Print one character per input, take out the input charactersWuyi the returnYES; - } Wu-(BOOL) Textfieldshouldclear: (Uitextfield *) TextField - { About $ - returnYES; - } --(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField A { + //nsstring *str = textfield.text; the //NSLog (@ "%@", str);//Get input string -[TextField Resignfirstresponder];//return keyboard Shrinkage $[UIView animatewithduration:0.1Animations:^{self.view.frame = CGRectMake (self.view.frame.origin.x, SELF.VIEW.FRAME.ORIGIN.Y + -, Self.view.frame.size.width, Self.view.frame.size.height);}];//as the keyboard shrinks, the whole moves down the the returnYES; the } the -- (void) didreceivememorywarning { in [Super didreceivememorywarning]; the //Dispose of any resources the can be recreated. the } About the @end
Uitextviewdelegate protocol
1- (void) Viewdidload2 {3 [Super Viewdidload];4Uitextview *textview = [[Uitextview alloc] Initwithframe:cgrectmake ( -, -, [UIScreen mainscreen].bounds.size.width- +, [UIScreen mainscreen].bounds.size.height- -)];5Textview.text =@"Although autoresizing is outdated, we still need to know about it. Autoresizing is Apple's early screen adaptation of the solution, iOS6 before fully capable, because the Apple phone only 3.5 inch screen, in addition to mobile app rarely support horizontal screen, so iOS developers basically do not have to adapt to the layout,";6Textview.font = [Uifont systemfontofsize: -];7 //textview.userinteractionenabled = NO;//prohibit user movement, infrequently used8Textview.textcolor =[Uicolor Redcolor];9 Ten [Self.view Addsubview:textview]; One //textview.delegate = self;//execution <UITextViewDelegate> Protocol proxy methods A -}
iOS base controls--uiimageview, Uitextfield