ios 平铺图片

编程入门 行业动态 更新时间:2024-10-24 06:34:47

ios <a href=https://www.elefans.com/category/jswz/34/1737757.html style=平铺图片"/>

ios 平铺图片

在进行ios开发时,我门有时候会为了节省安装包大小而采取用局部图片平铺作为背景图片。
做法:

1:在view的draeRect里面使用UIIMage的方法:drawAsPatternInRect:


  [plain]  view plain copy
  1. UIImage *imgQuestionBgBottom = [UIImage imageNamed:@"profile_arrow.png"];  
  2.   
  3.    UIImage *imgQuestionBgMiddle = [UIImage imageNamed:@"profile_arrow1.png"];      
  4.   
  5.    float tileHeight = 8;  
  6.   
  7.    float tileWidth = 9;  
  8.   
  9.    float imageHeight = tileHeight*5;  
  10.   
  11.    UIGraphicsBeginImageContext(CGSizeMake(tileWidth, imageHeight+imgQuestionBgBottom.size.height));  
  12.   
  13.    [imgQuestionBgMiddle drawAsPatternInRect:CGRectMake(0, 0, tileWidth, imageHeight)];  
  14.   
  15.    [imgQuestionBgBottom drawInRect:CGRectMake(0, imageHeight, imgQuestionBgBottom.size.width, imgQuestionBgBottom.size.height)];  
  16.   
  17.    UIImage* imgBg = UIGraphicsGetImageFromCurrentImageContext();  
  18.   
  19.    UIGraphicsEndImageContext();  
  20.   
  21.    self.leftTopImageView.image = imgBg;  
  22.   
  23.    self.leftTopImageView.frame = CGRectMake(0, 0, imgBg.size.width, imgBg.size.height);  



  2: [plain]  view plain copy
  1. UIImage *bgImg = [UIImageimageNamed:@"detailBg.png"];  
  2.   
  3.     UIColor *color = [[UIColoralloc] initWithPatternImage:bgImg];  
  4.   
  5.     UIView *bg = [[UIView alloc]initWithFrame:self.tableView.frame];  
  6.   
  7.     [bgsetBackgroundColor:color];  
  8.   
  9.     [color release];  
  10.   
  11.     [self.tableViewsetBackgroundView:bg];  
  12.   
  13.     [bg release];  

转载:

更多推荐

ios 平铺图片

本文发布于:2023-06-20 04:21:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/796006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平铺   图片   ios

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!