iphone picture stretch: resizableimagewithcapinsets

Source: Internet
Author: User

1 [[UIImage imagenamed:@ "button_textured_30"] resizableimagewithcapinsets:uiedgeinsetsmake (0, 5, 0, 5)];

Where insets this parameter format is (Top,left,bottom,right), from the top, left, bottom, right, respectively, draw a line on the picture, so that a picture added a box.

Only the part inside the box is stretched, and the outside of the box does not change.

The 4 parameters are the upper boundary, the left boundary, the lower boundary, the right boundary distance, or the negative value.

Where insets this parameter format is (Top,left,bottom,right), from the top, left, bottom, right, respectively, draw a line on the picture, so that a picture added a box. Only the part inside the box is stretched, and the outside of the box does not change. For example (20,5,10,5), meaning that the inner part of the rectangle can be stretched, while the rest remains unchanged.

It is said that the Stretchableimagewithleftcapwidth:topcapheight function can also be implemented, but it is not recommended to use this function in IOS5. Effects such as:

When the data has been modified, it becomes this:

Let's see how it's implemented.

The thermometer consists of three images:

Background map Thermometerbackground.png:

Scale drawing thermometercalibration:

The solution inside Calibration:

First add the background map to the Superview, and then add the scale chart and solution diagram to the background: (for simplicity, some unnecessary code has been omitted)

[Plain]View Plaincopy
  1. Add a background map to Superview
  2. Uiimageview *thermometerbackground = [[Uiimageview alloc] initwithframe:thermometer_frame];
  3. [Thermometerbackground setimage:[uiimage imagenamed:@ "Thermometerbackground.png"];
  4. [Self.view AddSubview:self.thermometerBackground];
  5. Add solution diagram to background map
  6. Uiimageview *thermometer = [[Uiimageview alloc]init];
  7. [Self.thermometerbackground AddSubview:self.thermometer];
  8. Add a scale chart to a background map
  9. Uiimageview *thermometercalibration = [[Uiimageview alloc] Initwithimage:[uiimage imagenamed:@ " Thermometercalibration.png "];
  10. [Self.thermometercalibration setframe:cgrectmake (0, ThermometerBackground.frame.size.width, thermometercalibration.image.size.height*thermometerbackground.frame.size.width/ ThermometerCalibration.frame.size.width)];
[Plain]View Plaincopy
    1. [Self.thermometerbackground addsubview:thermometercalibration];

Then, the image corresponding to the height is generated according to the degree;

[Plain]View Plaincopy < param name= "wmode" value= "Transparent" >
    1. uiimage* image = [UIImage imagenamed:@ "Thermometer.png"];
    2. Uiedgeinsets insets = uiedgeinsetsmake (20, 0, 25, 0);
    3. image = [Image resizableimagewithcapinsets:insets];
    4. int top = 10.00+ (38.00-temperature) *20.00;
    5. [Self.thermometer setframe:cgrectmake (0, Top, self.thermometerBackground.frame.size.width, Self.thermometerbackground.frame.size.height-top)];
[Plain]View Plaincopy
    1. [Self.thermometer Setimage:image];

Here, top this variable represents the height of the solution calculated according to the degree.

In this way, when changing the temperature temperature size, as long as the viewwillappear call this code, you can dynamically generate a thermometer picture.

iphone picture stretch: resizableimagewithcapinsets

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.