The idea of creating code for common Controls (UIButton, UILabel) for iOS development

Source: Internet
Author: User

Code creation button UIButton:

(i) Basic settings

Create an Intermediate "+" button

UIButton *addbtn = [[UIButton alloc] init];

Set the default background picture

[Addbtn setbackgroundimage:[uiimage imagenamed:@ "Addbuttonicon"] forstate:uicontrolstatenormal];

Set the background picture when pressed

[Addbtn setbackgroundimage:[uiimage imagenamed:@ "addbuttonicon-active"] forstate:uicontrolstatehighlighted];

Add Response Events

[Addbtn addtarget:self Action: @selector (Addbtndidclick) forcontrolevents:uicontroleventtouchupinside];

Add a button to the Tabbar

[Self addsubview:addbtn];

(b) Setting the size and position

Set the position of the "+" button

Self.addButton.centerX = Self.centerx;

Self.addButton.centerY = self.height * 0.5-1.5 * addbuttonmargin;

Set the size of the "+" button to the size of the picture

Self.addButton.size = Cgsizemake (Self.addButton.currentBackgroundImage.size.width, Self.addButton.currentBackgroundImage.size.height);

(iii) Implementation of the Click event Processing method Addbtndidclick

Code creation Uilabel:

Create and set the text below the "+" button to "add"

UILabel *ADDLBL = [[UILabel alloc] init];

Addlbl.text = @ "Add";

Addlbl.font = [Uifont systemfontofsize:10];

Addlbl.textcolor = [Uicolor Graycolor];

[Addlbl SizeToFit];

Set the location of the "Add" label

Addlbl.centerx = Self.addButton.centerX;

Addlbl.centery = Cgrectgetmaxy (self.addButton.frame) + 0.5 * addbuttonmargin + 0.5;

[Self ADDSUBVIEW:ADDLBL];

Other control code creation ideas : Set the size, position, set the basic state (such as background picture, title, text size, color), add the view to the parent view, and finally implement the corresponding interactive event processing method (if necessary)

The idea of creating code for common Controls (UIButton, UILabel) for iOS development

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.