Some properties of iOS Uitextfield,uibutton,uiwebview and tips for using iOS image resources

Source: Internet
Author: User

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

:



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.