Sometimes the UI is inconsistent with the actual frame, so we're going to stretch the picture.
uiimage* image = [[UIImage imagenamed:@ "Text_field_bg.png"] stretchableimagewithleftcapwidth:20 topcapheight:0]; Stretchableimagewithleftcapwidth make a picture have a stretch effect
The properties of Uitextfield are described in:
uitextfield* field = [[Uitextfield alloc] Initwithframe:cgrectmake (80, 10, 170, 30)]; _textfield = field; _textfield.autoresizingmask = uiviewautoresizingflexiblewidth;//automatically adjusts its position so that its left and right margins and Superview remain the same _ textfield.enablesreturnkeyautomatically = YES; Make return available at input _textfield.placeholder = @ "Please input:"; Set the value of hint _textfield.textalignment = nstextalignmentleft; Text on the left shows _textfield.borderstyle = Uitextborderstylenone; No Border _textfield.font = [Uifont systemfontofsize:18.0f]; Set Font Size _textfield.contenthorizontalalignment = Uicontrolcontenthorizontalalignmentcenter; _textfield.contentverticalalignment = Uicontrolcontentverticalalignmentcenter; These two make the text appear centered _textfield.clearbuttonmode = uitextfieldviewmodewhileediting; When entered, there is a clear button uiimage* image = [[UIImage imagenamed:@ "Text_field_bg.png"] stretchableimagewithleftcapwidth:20 to PCAPHEIGHT:0]; Stretchableimagewithleftcapwidth make the picture have a stretch effect 20 means that the left border of the picture 20 pixels can be stretched horizontally _textfield.delegate = self; Set proxy _textfield.background = image for TextField; Background setting _textfield.leftviewmode = Uitextfieldviewmodealways; CGRect frame = [_textfield frame]; Frame.size.width = 15; uiview* view1 = [[UIView alloc] initwithframe:frame]; _textfield.leftview = View1; Above a few words set the text with TextField left some distance [Self.view Addsubview:_textfield];
How to set up let Uitextfield only input in English, first let controller implement Uitextfielddelegate agent
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string{ if ([string length]) { Unichar single = [string characteratindex:0]; if (Single > ' A ' && single < ' z ') { return YES; } else{//input data format is incorrect NSLog (@ "format is incorrect"); [Textfield.text stringbyreplacingcharactersinrange:range withstring:@ "]; return NO; } } return YES;}
If you want the keyboard to pop up when you enter the interface, you can do this:
[_textfieldbecomefirstresponder];
The properties of UIButton are described in:
uibutton* button = [UIButton buttonwithtype:uibuttontypecustom]; Init a button, you can customize the background [button Setbackgroundimage:[[uiimage imagenamed:@ "[email protected]"] Stretchableimagewithleftcapwidth:20 topcapheight:0] forstate:uicontrolstatenormal]; Button.frame = CGRectMake (260,10, 49, 30); Set button background with normal and highlight two states [button Setbackgroundimage:[[uiimage imagenamed:@ "[email protected]"] Stretchableimagewithleftcapwidth:20 topcapheight:0] forstate:uicontrolstatehighlighted]; Button.frame = CGRectMake (260,10, 49, 30); [Button settitle:@ "OK" forstate:uicontrolstatenormal]; Set the button's text [button Settitlecolor:[myviewcontroller rgbcolorfromhexstring:@ "#333333" alpha:1.0f] forstate: UIControlStateNormal]; [Button Settitlecolor:[myviewcontroller rgbcolorfromhexstring:@ "#000000" alpha:1.0f] forstate: Uicontrolstatehighlighted]; [Button addtarget:self action: @selector (onclick) forcontrolevents:uicontroleventtouchupinside]; If the onclick has a colon, the button will be passed when the method is written. Like onclick: (ID) sender [self.view Addsubview:button];
The properties of UIWebView are described in:
uiwebview* WebView = [[UIWebView alloc] Initwithframe:cgrectmake (0, +, +, 480-46)]; _webview = WebView; Webview.delegate = self; nsurl* url = [Nsurl urlwithstring:@ "http://m.baidu.com"]; nsurlrequest* request = [Nsurlrequest Requestwithurl:url]; [WebView loadrequest:request]; [Self.view Addsubview:webview];
Code can be downloaded in http://download.csdn.net/detail/baidu_nod/7595369
: