IOS25---picture stretching

Source: Internet
Author: User

Controller:

////VIEWCONTROLLER.M//12-Drawing problems with pictures////Created by Xiaomage on 15/12/30.//2015 little brother. All rights reserved.//#import "ViewController.h"#import "Uiimage+xmgextention.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet UIButton*button;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //1.1 Creating a UIImage objectUIImage *image = [UIImage resizableimagewithlocalimagename:@"Car"];//methods for extending the system classes//UIImage *image = [UIImage imagenamed:@ "Car"]; //1.2 Get the size of the image    /*cgfloat imagewidth = image.size.width;    CGFloat imageheight = image.size.height; */        //1.3 Returns a protected and stretched picture--->capinsets: which places to protect: the height of the protection of the picture half, the left to protect the width of the picture half, the right to protect the width of half minus one, below the protection height of half minus one.        Only the area of the middle 1*1 is stretched. //Way One    /*UIImage *resizableimage = [Image resizableimagewithcapinsets:uiedgeinsetsmake (ImageHeight * 0.5, ImageWidth * 0.5,    ImageHeight * 0.5-1, ImageWidth * 0.5-1)]; Uiimageresizingmodetile, tiling uiimageresizingmodestretch, stretching (scaling) UIImage *resizableimage = [Image Resizableimagewi Thcapinsets:uiedgeinsetsmake (ImageHeight * 0.5, ImageWidth * 0.5, ImageHeight * 0.5-1, ImageWidth * 0.5-1) ResizingMode    : Uiimageresizingmodetile]; */        //Mode two    /*///right area to be protected = width-leftcapwidth-1 of picture//Bottom cap = height-topcapheight-1 UIImage *resizableimag    e = [Image stretchableimagewithleftcapwidth:imagewidth * 0.5 topcapheight:imageheight * 0.5]; */        //2. Set the picture to the button[Self.button setbackgroundimage:image forstate:uicontrolstatenormal]; }@end

UIImage Extensions, Categories:

// //   uiimage+xmgextention.h//  12-picture stretching problem //#import <uikit/ uikit.h>@interface UIImage (xmgextention)  // category / *  */+ (Instancetype) Resizableimagewithlocalimagename: (NSString *) localimagename; @end
////uiimage+xmgextention.m//#import "Uiimage+xmgextention.h"@implementationUIImage (xmgextention)+ (Instancetype) Resizableimagewithlocalimagename: (NSString *) localimagename{//Create a Picture objectUIImage *image =[UIImage Imagenamed:localimagename]; //get the dimensions of a pictureCGFloat imagewidth =Image.size.width; CGFloat imageheiht=Image.size.height; //returns an extruded and protected picture    return[Image Stretchableimagewithleftcapwidth:imagewidth *0.5TOPCAPHEIGHT:IMAGEHEIHT *0.5 ];}@end

IOS25---picture stretching

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.