In iOS development, uibutton allows you to set text switching when both the image text and the departure button are set.

Source: Internet
Author: User

When using UIBUtton, we sometimes need to set pictures and text at the same time. The following code is for reference only:

UIButton * _ backButton = [UIButton
ButtonWithType: UIButtonTypeCustom];

[_ BackButton setFrame: CGRectMake (12,
8, 64, 28)];

[_ BackButton setTitle: @ "return"
ForState: UIControlStateNormal]; // sets the font of the button when it is not selected.

_ BackButton. titleLabel. font = [UIFont
SystemFontOfSize: 14.0f]; // set the font size of the button.

[_ BackButton setBackgroundImage: [UIImage
ImageNamed: @ "backButton.png"]
ForState: UIControlStateNormal]; // sets the button background to display the image.

[Self. view addSubview: _ backButton];

In the event of the above operation accident, we can also set the button to display different text and images in the selected (pressed) and normal (not selected) status,

UIButton * _ backButton = [UIButton
ButtonWithType: UIButtonTypeCustom];

[_ BackButton setFrame: CGRectMake (12,
8, 64, 28)];

[_ BackButton setTitle: @ "return"
ForState: UIControlStateNormal];

[_ BackButton setTitle: @ "Down" forState: UIControlStateHighlighted];

[_ BackButton setBackgroundColor: [UIColor clearColor];

[_ BackButton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];

_ BackButton. titleLabel. font = [UIFont
SystemFontOfSize: 14.0f];

[_ BackButton setBackgroundImage: [UIImage
ImageNamed: @ "backButton.png"]
ForState: UIControlStateNormal];

[_ BackButton setBackgroundImage: [UIImage imageNamed: @ "DownButton.png"] forState: UIControlStateNormal];

[_ ToolBar addSubview: _ backButton];

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.