平铺图片"/>
ios 平铺图片
在进行ios开发时,我门有时候会为了节省安装包大小而采取用局部图片平铺作为背景图片。做法:
1:在view的draeRect里面使用UIIMage的方法:drawAsPatternInRect:
- UIImage *imgQuestionBgBottom = [UIImage imageNamed:@"profile_arrow.png"];
- UIImage *imgQuestionBgMiddle = [UIImage imageNamed:@"profile_arrow1.png"];
- float tileHeight = 8;
- float tileWidth = 9;
- float imageHeight = tileHeight*5;
- UIGraphicsBeginImageContext(CGSizeMake(tileWidth, imageHeight+imgQuestionBgBottom.size.height));
- [imgQuestionBgMiddle drawAsPatternInRect:CGRectMake(0, 0, tileWidth, imageHeight)];
- [imgQuestionBgBottom drawInRect:CGRectMake(0, imageHeight, imgQuestionBgBottom.size.width, imgQuestionBgBottom.size.height)];
- UIImage* imgBg = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- self.leftTopImageView.image = imgBg;
- self.leftTopImageView.frame = CGRectMake(0, 0, imgBg.size.width, imgBg.size.height);
- UIImage *bgImg = [UIImageimageNamed:@"detailBg.png"];
- UIColor *color = [[UIColoralloc] initWithPatternImage:bgImg];
- UIView *bg = [[UIView alloc]initWithFrame:self.tableView.frame];
- [bgsetBackgroundColor:color];
- [color release];
- [self.tableViewsetBackgroundView:bg];
- [bg release];
转载:
更多推荐
ios 平铺图片
发布评论