UIButton for ios development click two icons for conversion

Source: Internet
Author: User

Now I want to define a UIButton. This button has two images. One is the background image and the other is the image 1. I set the background image through setBackgroundImage and use setImage to set the display image, but because the image is larger than the size of the buttons I set, the result is that the image exceeds the button frame ..... when the first button overlaps two images, the last two are loaded separately... the source code is as follows: www.2cto. comUIButton * btn1 = [UIButton buttonWithType: bytes]; [btn1 setFrame: CGRectMake (10, 10, 50, 50)]; [btn1 setBackgroundImage: [UIImage imageNamed: @ "ui4.png"] forState: UIControlStateNormal]; [btn1 setImage: [UIImage imageNamed: @ "icon0.png"] forState: UIControlStateNormal]; condition = success; [self addSubview: btn1]; UIButton * btn2 = [UIButton buttonWithType: Custom]; [btn2 setFrame: CGRectMake (65, 10, 50, 50)]; [btn2 setBackgroundImage: [UIImage imageNamed: @ "ui4.png"] forState: Custom]; custom = custom; [self addSubview: btn2]; UIButton * btn3 = [UIButton buttonWithType: Custom]; [btn3 setFrame: CGRectMake (120, 10, 50, 50)]; btn2.contentMode = UIViewContentModeCenter; [btn3 orientation: [UIImage imageNamed: @ "icon0.png"] forState: UIControlStateNormal]; [self addSubview: btn3];

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.