对图片的设置

合成图片。下载图片。拉伸图片


//合成图片

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];

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 3,967评论 5 10
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 6,822评论 4 26
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 900评论 0 3
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 916评论 0 3
  • 一切交往都有不可超越的最后界限。在两个人之间,这种界限是不清晰的,然而又是确定的。一切麻烦和冲突都起于无意中想突破...
    TigerFeng阅读 140评论 0 1