UIImage-----------文本解释的图片框拉伸(小三角在中间的情况)

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.view.backgroundColor = [UIColor cyanColor];

UIImage *image = [self stretchableImage];

UIImageView *popImg = [[UIImageView alloc] initWithImage:image];

[self.view addSubview:popImg];

CGFloat tempWidth = 300/2+image.size.width/2;

UIGraphicsBeginImageContextWithOptions(CGSizeMake(tempWidth, 80), NO, [UIScreen mainScreen].scale);

[image drawInRect:CGRectMake(0, 0, tempWidth, 80)];

UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

popImg.image = [tempImage stretchableImageWithLeftCapWidth:image.size.width *0.2 topCapHeight:image.size.height*0.5];

popImg.frame = CGRectMake(10, 300, 300, 80);

}

- (UIImage *)stretchableImage {

UIImage *image = [UIImage imageNamed:@"location_tips@2x"];

return [image stretchableImageWithLeftCapWidth:image.size.width *0.7 topCapHeight:image.size.height *0.5];

// 0.7大于0.5

}

你可能感兴趣的:(UIImage-----------文本解释的图片框拉伸(小三角在中间的情况))