The titl methods that are set up in UIButton include the following:
-(void) Settitle: (NSString *) title forstate: (uicontrolstate) state; -(void) Setattributedtitle: (nsattributedstring *) title forstate: (uicontrolstate) state @property ( Nonatomic,readonly, retain) NSString *currenttitle; @property (nonatomic,readonly, retain) UILabel *titlelabel;
In the definition of UIButton, often use Titlelabel.text set the value of UIButton, but run out does not show anything, does not work AH!!! , how is this going to happen? Is it the API bug??
1. In fact, the normal use of UIButton when the title is to correspond to the ControlState button, because UIButton inherit Uicontrol, in the setting is worth the object state, so it will be used
Settitle: (NSString *) title forstate: (uicontrolstate) state setting title;
2.setAttributedTitle is the method after iOS6, it is very simple to use, no special description. Examples are as follows:
[UIButton setattributedtitle:[[nsattributedstring alloc]initwithstring:@ "3333333"] Forstate:uicontrolstatenormal];
3. The corresponding Currenttitle is the title value of the/normal/highlighted/selected/disabled state, and the attribute is readonly;
4. As for the Titlelabel is set when why not show, more magical. After checking the official documents, I found out that the real reason was again: (Below is the result of I print the Titlelabel object using UIButton)
PO Uibutton.titlelabel
0x7575800; frame = (0000'11111111'0x7572980>>
See here, do you understand?
The default UIButton titlelable is not set frame, and Hidden=yes, as long as you set these 2 values can be displayed normally,
No matter how you produce UIButton:
UIButton *uibtn = [[UIButton alloc]initwithframe:cgrectmake (0)];
*UIBTN = [UIButton buttonwithtype:uibuttontypecustom];
[Uibtn setframe:cgrectmake (0, 100, 100, 30)];
are the same;
In short, above is I encountered 2 times use Titlelabel not show summary, hope to be helpful later. It is recommended to use the first way to set the title without having so much trouble ...