Some common knowledge points of UIButton

Source: Internet
Author: User
Tags button type

Some common information about UIButton:


    Create button UIButton *button = [UIButton buttonwithtype:uibuttontypecustom]; /* Uibuttontype button type: (the first two are common types) Uibuttontypecustom = 0,//No button type//custom type UI      Buttontypesystem Ns_enum_available_ios (7_0),//Standard system button//system type, std type uibuttontypedetaildisclosure, Uibuttontypeinfolight, Uibuttontypeinfodark, uibuttontypecontactadd, uibuttontyperoundedrect = UIBut Tontypesystem,//Deprecated, use Uibuttontypesystem instead *//Set button Properties Button.frame = CGRectMake (50, 100 , 200, 50);//Set position and size (required one step) Button.backgroundcolor = [Uicolor yellowcolor];//background color [button settitle:@ "Login" forSt ate:uicontrolstatenormal];//button text, normal state [button settitle:@ "Press" forstate:uicontrolstatehighlighted];//, highlight status */* U Icontrolstate button Controller status: UIControlStateNormal = 0,//normal status Uicontrolstatehighligh Ted = 1 << 0,//used when Uicontrol IsHIghlighted is set highlighting state, (button pressed) uicontrolstatedisabled = 1 << 1,//unavailable status Uicontrolst ateselected = 1 << 2,//flag usable by app (see below) Check Status Uicontrolstateapplication =               0x00ff0000,//additional flags available for application use uicontrolstatereserved = 0xff000000 Flags reserved for internal the framework use *///button.enabled = no;//is set to unavailable (default is yes, available)//button . Selected = yes;//is set to checked (default is no, unchecked)//other picture and background picture of button properties//Top level (and text layer) based on status: Set the normal state, the highlighted state is also displayed, set the highlight state, the normal state [Button setimage:[uiimage imagenamed:@ "001.png"] forstate:uicontrolstatenormal];//normal picture (and text layer)//Picture is added in front of text by default  Face, and the first layer of text, will squeeze the text to the back.    Note the size of the button, prevent the text space is not enough, become "..." [Button setimage:[uiimage imagenamed:@ "10.png"] forstate:uicontrolstatehighlighted];//the picture in the highlighted State [button Setbackgroundimage:[uiimage imagenamed:@ "002.jpg"] forstate:uicontrolstatenormal];//background picture in normal state [button SETBACKgroundimage:[uiimage imagenamed:@ "5.png"] forstate:uicontrolstatehighlighted];//background picture in highlighted state//Add Picture: PNG image can omit suffix,    Add suffixes to other images.  [Button Settitlecolor:[uicolor Bluecolor] forstate:uicontrolstatenormal];//Set the button font color, like the picture, set the normal state, the highlighted state also changed.    Set the highlight state, the normal state does not change.  If not set, the default for the system type is blue. Custom type is equivalent to no settings, colorless/white//About picture display: The system type does not display the topmost (and the text layer) of the picture, want to show the top of the picture needs to change to the custom type [button Settintcolor:[uicolor r edcolor]];//change the topmost font color and picture background color//about font color and picture back color: System type You can change the top-level font color and the picture background color with the Settintcolor method (because you can see the background color of the picture if you can't display the picture).    Also, if the font color has been set individually before or after, the Settintcolor method does not change the color of the font, only the background color of the picture.    The Settintcolor method is invalid for a button of type custom. Button.titleLabel.font = [Uifont systemfontofsize:15.2];//changes font size.  The font becomes a separate layer//other: button.showstouchwhenhighlighted = yes;//is set to YES after the button is clicked, the button glows. The default is no//press the CMD key, mouse click in.    You can see several other adjacent settings, such as the shadow setting of the caption text, etc.//Add the button to the parent view [Self.view Addsubview:button]; Free space//button is created by the convenience builder, no alloc, no release//summary: Generally, the simple UIButton object consists of two layers, the next layer is UIButton, the above layer is uibuttonlabel (this layer can add picture uiimageview), display the button text (button name)//If you add a button background image, in the middle of UIButton and Uibuttonlabel will be added a layer of uiimageview.    If you change the font size, you will add a layer of font to the top. After running the program, you can click Debug View Hierarchy (Debug views level) above the debugging window to view//Of course, UIButton as a subclass of UIView, you can continue to add additional view sub-view


Reference Document: http://blog.csdn.net/heng615975867/article/details/38873647

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Some common knowledge points of UIButton

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.