合成图片。下载图片。拉伸图片
//合成图片
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];
//设置图片偏移量
thirdVC.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
//关闭上下文
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();
//关闭上下文
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];
网友评论