iOS Stage Learning 27th Day notes (Uibutton-uiimageview's introduction)

Source: Internet
Author: User
Tags border color

iOS Learning (UI) Knowledge Point Grooming

First, about the introduction of UIButton

1) Concept: UIButton is a common control that triggers the corresponding function by clicking

2) Several commonly used states of the UIButton
1. UIControlStateNormal normal state
2, uicontrolstatehighlighted highlight State
3, uicontrolstateselected selected status, when the button's selected is set to Yes before triggering

3) Several events commonly used in UIButton
1. UIControlEventTouchUpInside Button Press and lift the event
2, Uicontroleventtouchdown Button press the event
3, Uicontroleventtouchdownrepeat button multiple Click Trigger Event

4) UIButton Initialization of the instance code

1UIButton *button =[[UIButton alloc] init];2Button.frame = CGRectMake ( -, -, -, -);3Button.backgroundcolor =[Uicolor Clearcolor];4[Button Settitle:@"Button 1 Normal state"Forstate:uicontrolstatenormal];5[Button Settitle:@"Button 1 Highlight State"forstate:uicontrolstatehighlighted];6[Button Settitle:@"button 1 Check status"forstate:uicontrolstateselected];7 8 //Trigger event When button is clicked9 [button addtarget:self action: @selector (buttontapped:) forcontrolevents:uicontroleventtouchupinside];Ten //Trigger event when button is pressed One [button addtarget:self action: @selector (Buttontappeddown:) Forcontrolevents:uicontroleventtouchdown]; A //button Double-click Trigger Event - [button addtarget:self action: @selector (Buttontappeddown:) forcontrolevents:uicontroleventtouchdownrepeat]; - //set the font color for button highlighting the [button Settitlecolor:[uicolor Lightgraycolor] forstate:uicontrolstatehighlighted]; - //the button font becomes a bold font of size 35th -Button.titleLabel.font = [Uifont boldsystemfontofsize: *]; - //Set rounded corners +Button.layer.cornerRadius =5. F; - //Set Border Width +Button.layer.borderWidth =2.1; A //Set Border color atButton.layer.borderColor =[Uicolor Lightgraycolor]. Cgcolor; -  //set the button background image -UIImage *imagenormal = [UIImage imagenamed:@"Camera"]; - //set imagenormal for the normal picture of the button - [button Setimage:imagenormal forstate:uicontrolstatenormal]; -      inUIImage *imagehightlight = [UIImage imagenamed:@"Camera2"]; - //set the picture of Imagehightlight as the highlight of the button to [button Setimage:imagehightlight forstate:uicontrolstatehighlighted]; + //when the button set the picture and did not set the highlighted state of the picture, cancel the highlight state, the default is Yes -button.adjustsimagewhenhighlighted =YES;  the[Self.window Addsubview:button];


5) Prevent the button multiple Click repeatedly submit data instance code

1 [button addtarget:self action: @selector (buttontapped:) forcontrolevents:uicontroleventtouchupinside];3- (void) buttontapped: (UIButton *) button4 {5     //Set button is not clickable6button.userinteractionenabled =NO; 8     //deferred execution method prevents the button from being clicked quickly or does not want the click to cause an error9[Self performselector: @selector (delaymethod:) Withobject:button Afterdelay:1];  One } A  - //delay method, set button to clickable state -- (void) Delaymethod: (UIButton *) button the { -button.userinteractionenabled =YES;  -}

Ii. Introduction to Uiimageview

1) Concept: Uiimageview is a control that is dedicated to displaying pictures in iOS

2) Uiimageview Initialization of the instance code

1Uiimageview *imageview =[[Uiimageview alloc] init];2Imageview.frame = CGRectMake (0,0, Self.view.frame.size.width, self.view.frame.size.width);3Imageview.backgroundcolor =[Uicolor Whitecolor];4Imageview.center =Self.view.center;5 6     //tag sets the unique identity of the control, and the value cannot be duplicated7Imageview.tag = -;8 9     //Uiimageview The Clipstobounds property, set to Yes when out of the section, not to displayTenImageview.clipstobounds =YES; One  A     //read a picture -UIImage *image = [UIImage imagenamed:@"icon"]; -Imageview.image =image; the  -     //set up picture display mode -Imageview.contentmode =Uiviewcontentmodescaleaspectfill; -  +     //Open ImageView User interaction Note: To implement a picture Click event This property must be set to Yes -imageview.userinteractionenabled =YES; + [Self.view Addsubview:imageview]; A  at     //Add a Click event for Uiimageview -UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] Initwithtarget:self
Action: @selector (imageviewtapped:)];
-[ImageView Addgesturerecognizer:tap];


3) Several filling modes commonly used in Ui_imageview
1. Uiviewcontentmodescaletofill stretches the image to make it full of uiimageview
2, Uiviewcontentmodescaleaspectfill stretch image so that it is not deformed, and full of Uiimageview
3, Uiviewcontentmodescaleaspectfit tensile imgage so that it does not deform, and fully displayed in the Uiimageview

4) UITapGestureRecognizer can add a click method to other controls in addition to adding a click method to Ui_imageview
such as: Ui_lable, Ui_view ... such as

5) Three ways to get pictures in iOS
Method One:

1 //load a picture object into memory2UIImage *image1 = [UIImage imagenamed:@"Camera"];3Cgsize size =image1.size;4NSLog (@"size.w%f size.h%f", Size.width, size.height);5 //if the format of the picture is PNG, the suffix can be omitted and other formats cannot be omitted6UIImage *image2 = [UIImage imagenamed:@"Icon.jpeg"];

Method Two:

//  read Icon.jpegnsstring *imagepath3 = [[NSBundle mainbundle] Pathforresource: @ "    icon" ofType:@"jpeg"*image3 =*imagepath3 _1 = [[NSBundle mainbundle] Pathforresource:@ "icon.jpeg"*image3_1 = [[ UIImage alloc] initwithcontentsoffile:imagepath3_1];

Method Three:

1 nsstring *imagepath = [[NSBundle mainbundle] Pathforresource:@ "icon" ofType: @" JPEG " ]; 2 3  UIImage *image4 = [UIImage Imagewithcontentsoffile:imagepath];

iOS Stage Learning 27th Day notes (Uibutton-uiimageview's introduction)

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.