The IOS UI Learning Tutorial uses code to create Button_ios

Source: Internet
Author: User

This article uses code to create a button that is divided into 5 steps, respectively:

1, define a button, according to the definition of location can be defined as local variables or global variables;

2, initialization button, generally using a rectangular initialization;

3, set the button control of other properties, such as background pictures, or background color, or button display text and other attributes;

4, add the response event and write the function content of the response event;

5. Load the created control into the window.

Five steps for specific operations see the following figure:

The specific code is as follows:

UIButton *btn;
  BTN = [[UIButton alloc]initwithframe:cgrectmake (0, 418, 760)];
  UIImage *img = [uiimage imagenamed:@ "fa.jpg"];
  [Btn settitle:@ "SDFDSFD" forstate:uicontrolstatenormal];
  [Btn setbackgroundimage:img forstate:uicontrolstatenormal];
  [Btn addtarget:self action: @selector (haha:) forcontrolevents:uicontroleventtouchupinside];
  [Self.view ADDSUBVIEW:BTN];

Response Event code:

 -(void) haha: (ID) sender{
  NSLog (@ "btn was clicked");
 }

The above is the entire content of this article, I hope to help you learn.

Related Article

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.