iOS Development UI Chapter-add buttons and tag parameter descriptions in Uiimageview

Source: Internet
Author: User

First, the tag parameter

A view typically has only one parent view and multiple child views, which can be removed by using the child view's tag in development. The method is Viewwithtag:

Cue point: In Xib, if you want to get the corresponding control (property) through the tag parameter, do not set the tag parameter to 0, because all objects in Xib have a default tag of 0 and the object is set to 0.

Second,Add a button in ImageView
(1) Comparison of ImageView and buttons

You can place multiple pictures (4) Inside the button, and only one picture in ImageView.

(2) Description:

ImageView can only display one picture, and we know that all UI controls are inherited from UIView, and that all views are containers, and that it's easy to add something to the inside. Can you add a button to the ImageView?

(3) Action to add a button to the ImageView

There are usually two ways to create a control, one to drag directly on the storyboard or Xib interface designer, and another to create it in the form of handwritten code.
Dragging on the interface designer doesn't add a button to the ImageView, so let's try the handwritten code.

The code is as follows:

1 #import "YYViewController.h" 2  3 @interface Yyviewcontroller () 4 @end 5  6 @implementation Yyviewcontroller 7
   8-(void) Viewdidload 9 {Ten     [super viewdidload];11     ///Uiimageview default does not allow user interaction     Uiimageview * ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (0, +, +)];14     [Self.view addsubview:imageview];15     Imageview.backgroundcolor = [Uicolor redcolor];16     imageview.userinteractionenabled = YES;17     UIButton *btn = [UIButton buttonwithtype:uibuttontypecontactadd];19     [ImageView addsubview:btn];20     21     [btn addtarget:self Action: @selector (click) forcontrolevents:uicontroleventtouchupinside];22}23-(void) click25 {     NSLog (@ "Touch Me")}28 @end

(4) Execution effect (after adding + button, click):

(5) Attention points:

In the code above, imageview.userinteractionenabled = YES, the function is to set ImageView to allow the user to interact.

ImageView default is to not allow user interaction, this can be viewed by viewing the ImageView property sidebar in the interface designer.

Note the properties of the default state

iOS Development UI Chapter-add buttons and tag parameter descriptions in Uiimageview

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.