Problem:
Create a UIButton object, set the object display Type "button", and then modify the text size, it is natural to point out the object's Font property, but found that the property has been deprecated in 2.0.3.0, iOS is not recommended. How should I modify the text size of the UIButton object ?
Figure 1-1: The Font property hint of the UIButton object is discarded.
Figure 1-2:The Font property of the UIButton class is marked as Ns_deprecated_ios
Workaround:
After xcode3.0, it is recommended to use the UIButton object 's properties Titlelabel to set the text size.
The code is as follows:
UIButton *btn =[[UIButton alloc]init]; CGFloat btnx= the; CGFloat Btny= labely+Labelh; CGFloat BTNW= (vieww-2*btnx); CGFloat BTNH= -; Btn.frame=CGRectMake (btnx, Btny, BTNW, BTNH); UIImage*btnimgnormal = [UIImage imagenamed:@"Buttongreen.png"]; [Btn Setbackgroundimage:btnimgnormal Forstate:uicontrolstatenormal]; UIImage*btnimghighlighted = [UIImage imagenamed:@"Buttongreen_highlighted.png"]; [Btn setbackgroundimage:btnimghighlighted forstate:uicontrolstatehighlighted]; [BTN Settitle:@"Download"Forstate:uicontrolstatenormal]; Btn.titleLabel.font =[uifont systemfontofsize:16]; [Self.view addsubview:btn];
After using Titlelabel to set the text size, try not to use Settitle:forstate: instead, use Titlelabel.text to set the UIButton object 's text as "button OK", but the button text remains "button".
Note: UIButton Some properties are required, such as setting the button text, in the following four states:
UIControlStateNormalUIControlStateHighlightedUIControlStateDisabledUIControlStateSelected
For example:
[BTN Settitle:@ " button " Forstate:uicontrolstatenormal];
So we can only set the button text by Settitle:forstate: method.
Beginner iOS Problems (iii) UIButton modifying text size issues