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
- Add a background map to Superview
- Uiimageview *thermometerbackground = [[Uiimageview alloc] initwithframe:thermometer_frame];
- [Thermometerbackground setimage:[uiimage imagenamed:@ "Thermometerbackground.png"];
- [Self.view AddSubview:self.thermometerBackground];
- Add solution diagram to background map
- Uiimageview *thermometer = [[Uiimageview alloc]init];
- [Self.thermometerbackground AddSubview:self.thermometer];
- Add a scale chart to a background map
- Uiimageview *thermometercalibration = [[Uiimageview alloc] Initwithimage:[uiimage imagenamed:@ " Thermometercalibration.png "];
- [Self.thermometercalibration setframe:cgrectmake (0, ThermometerBackground.frame.size.width, thermometercalibration.image.size.height*thermometerbackground.frame.size.width/ ThermometerCalibration.frame.size.width)];
[Plain]View Plaincopy
- [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" >
- uiimage* image = [UIImage imagenamed:@ "Thermometer.png"];
- Uiedgeinsets insets = uiedgeinsetsmake (20, 0, 25, 0);
- image = [Image resizableimagewithcapinsets:insets];
- int top = 10.00+ (38.00-temperature) *20.00;
- [Self.thermometer setframe:cgrectmake (0, Top, self.thermometerBackground.frame.size.width, Self.thermometerbackground.frame.size.height-top)];
[Plain]View Plaincopy
- [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