5.ios code to create controls and typography

Source: Internet
Author: User

1.UIView

The control that is added to the view is x, y is calculated from the upper left corner of the view

2.UIButton

UIButton contains uilable and Uiimageview

Set text to use Settitle, can not directly change titlelabel.text because I do not know the state of the text

Titlelabel.font when setting text font

3. Nsarray Lazy Loading


@property (nonatomic, strong) Nsarray *apps; @implementation mjviewcontroller-(void) viewdidload{[Super Viewdidload];        Add application information//0. Total number of columns (one row up to 3 columns) int totalcolumns = 3;    1. Size of application cgfloat APPW = 85;        CGFloat APPH = 90; 2. Clearance = (width of Controller View-3 * application width)/4 cgfloat Marginx = (Self.view.frame.size.width-totalcolumns * appw)/(Totalcolu    MNS + 1);        CGFloat marginy = 15; 3. Create the corresponding box according to the number of applications (index 0 ~ one) for (int index = 0; index<self.apps.count; index++) {//3.1. Create 1 small box U        IView *appview = [[UIView alloc] init];            Set background color//Appview.backgroundcolor = [Uicolor Redcolor];        3.2. Calculate the position of the box//Calculate line number and column number int row = Index/totalcolumns;        int col = index% Totalcolumns;        Calculate x and y cgfloat AppX = marginx + col * (APPW + Marginx);        CGFloat Appy = + Row * (APPH + marginy);                Set Frame Appview.frame = CGRectMake (AppX, Appy, APPW, APPH); 3.3. Add a BoxFrame to the Controller view [Self.view Addsubview:appview];                3.4. Add the internal gizmo//3.4.0.index position corresponding application information nsdictionary *appinfo = Self.apps[index];        3.4.1. Add picture Uiimageview *iconview = [[Uiimageview alloc] init];        Set position cgfloat iconw = 45;        CGFloat iconh = 45;        CGFloat IconX = (appw-iconw) * 0.5;        CGFloat icony = 0;        Iconview.frame = CGRectMake (IconX, Icony, Iconw, Iconh);        Set Picture Iconview.image = [UIImage imagenamed:appinfo[@ "icon"];                [Appview Addsubview:iconview];        3.4.2. Add name UILabel *namelabel = [[UILabel alloc] init];        Set position cgfloat Namew = APPW;        CGFloat Nameh = 20;        CGFloat NameX = 0;        CGFloat Namey = Icony + iconh;        Namelabel.frame = CGRectMake (NameX, Namey, Namew, Nameh);        Set Text Namelabel.text = appinfo[@ "name"];        Set Font namelabel.font = [Uifont systemfontofsize:13];      Set Text Center alignment  Namelabel.textalignment = Nstextalignmentcenter;                [Appview Addsubview:namelabel];        3.4.3. Add Download button UIButton *downloadbtn = [[UIButton alloc] init];        Set position cgfloat DOWNLOADX = 12;        CGFloat Downloady = Namey + Nameh;        CGFloat DOWNLOADW = appW-2 * DOWNLOADX;        CGFloat downloadh = 20;        Downloadbtn.frame = CGRectMake (DOWNLOADX, Downloady, DOWNLOADW, downloadh);        Set the default background UIImage *normalimage = [UIImage imagenamed:@ "Buttongreen"];        [Downloadbtn setbackgroundimage:normalimage Forstate:uicontrolstatenormal];        Set the highlighted background UIImage *highimage = [UIImage imagenamed:@ "buttongreen_highlighted"];        [Downloadbtn setbackgroundimage:highimage forstate:uicontrolstatehighlighted];        Set the text of the button [downloadbtn settitle:@ "Download" forstate:uicontrolstatenormal];        It is not recommended to directly get the label inside the button set text//DownloadBtn.titleLabel.text = @ "5435345345"; Sets the font downloadbtn.title for the button textLabel.font = [Uifont systemfontofsize:13];    [Appview ADDSUBVIEW:DOWNLOADBTN]; }}-(Nsarray *) apps{if (_apps = = nil) {//Initialize//1. Get Plist's full path nsstring *path = [[Nsbund]                Le Mainbundle] pathforresource:@ "app.plist" oftype:nil];    2. Load array _apps = [Nsarray Arraywithcontentsoffile:path]; } return _apps;}


5.ios code to create controls and typography

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.