UIButton background image resize, uibutton background image

Source: Internet
Author: User

UIButton background image resize, uibutton background image

Generally, the button adds a background image.

UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (60,100,)];

[Button setTitle: @ "Test Button" forState: UIControlStateNormal]; // Image with without cap insets

UIImage * buttonImage = [UIImage imageNamed: @ "blueButton"];

[Button addTarget: self action: @ selector (buttonPressed :) forControlEvents: UIControlEventTouchUpInside];

[Button setBackgroundImage: buttonImage forState: UIControlStateNormal];

[[Self view] addSubview: button];

If the size of the background image does not match that of the button frame. If the size of the frame is greater than the size of the background image, the system will automatically raise the image.

The result is that the image is enlarged, causing deformation. (This is not what we expected. If you have a good artist and want to provide any graph, you can ignore the following method)

Modify the above uiimage creation as follows:

UIImage * buttonImage = [UIImage imageNamed: @ "blueButton"] resizableImageWithCapInsets: UIEdgeInsetMake (,)];

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.