合成圖片屡穗。下載圖片刚操。拉伸圖片
//合成圖片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:imageView];
//0.0視圖清晰度0.5視圖會模糊掉
UIGraphicsBeginImageContextWithOptions( CGSizeMake( self.view.bounds.size.width, self.view.bounds.size.height), NO, 0.0);
UIImage *image1 = [UIImage imageNamed:@"8.jpg"];
UIImage *image2 = [UIImage imageNamed:@"13.jpg"];
[image1 drawInRect:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height/3)];
[image2 drawInRect:CGRectMake(0, self.view.bounds.size.height/3, self.view.bounds.size.width, self.view.bounds.size.height/3)];
UIImage *image3 = [UIImage imageNamed:@"8.jpg"];
//越接近添加語句就越是最前視圖
[image3 drawInRect:CGRectMake(0, (self.view.bounds.size.height/3) *2, self.view.bounds.size.width, self.view.bounds.size.height/3)];
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
thirdVC.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
thirdVC.tabBarItem.selectedImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//設(shè)置圖片偏移量
thirdVC.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
//關(guān)閉上下文
UIGraphicsEndImageContext();
//合成圖片和下載圖片
合成圖片
UIGraphicsBeginImageContextWithOptions(CGSizeMake(200, 100),NO, 0.0);
[mage1? drawInRect:CGRectMake(0, 0, 100, 100)];
[mage2 drawInRect:CGRectMake(100, 0, 100, 100)];
self.image3.image = UIGraphicsGetImageFromCurrentImageContext();
//關(guān)閉上下文
UIGraphicsEndImageContext();
下載圖片
-(UIImage*)imageWithURL:(NSString*)URLStr{
NSURL* url = [NSURL URLWithString:URLStr];
NSData* data = [NSData dataWithContentsOfURL:url];
UIImage* image = [UIImage imageWithData:data];
return image;
}
拉伸圖片
UIView * messageView = [[UIView alloc] initWithFrame:CGRectMake(X, 0, 200, height + 20)];
messageView.tag = 101;
NSString * imageName = isMe == YES ? @"bubbleSelf":@"bubble";
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, height + 20)];
UIImage* oldImage = [UIImage imageNamed:imageName];
UIImage* newImage = [oldImage stretchableImageWithLeftCapWidth:20 topCapHeight:10];
imageView.image = newImage;
[messageView addSubview:imageView];