Beginner iOS Problems (iii) UIButton modifying text size issues

Source: Internet
Author: User

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

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.