lee*_*hou 42 iphone uicolor ios
我有一个视图,并希望通过UIImage为此视图设置backGroudColor.代码如下:
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backImage.png"]];
Run Code Online (Sandbox Code Playgroud)
问题是:backImage'frame比视图小.如何将UIImage拉伸到我的视野.我知道使用UIImageView可以达到.
有人有好主意吗?
更新:
我无法上传一张图片.
像这样:backImge的大小是30*30,当我使用时,我的视图大小是1024*700 myview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backImage.png"]];
结果是myview的backGroup有很多'backImage.png'.我的目标是有一个'backImage.png'充满了我的观点.
小智 120
试试.
self.layer.contents = (id)[UIImage imageNamed:@"freshBackground.png"].CGImage;
self.view.layer.contents = UIImage(named: "freshBackground")!.cgImage
Run Code Online (Sandbox Code Playgroud)
Kju*_*uly 24
据我所知,你无法直接调整背景的图案图像.最简单的方法是更改图像以适合父视图的帧大小.或者,您可以重绘图像以适合父视图的大小.
UIView * yourView = [[UIView alloc] initWithFrame:CGRectMake(10.f, 100.f, 300.f, 100.f)];
UIImage * targetImage = [UIImage imageNamed:@"backImage.png"];
// redraw the image to fit |yourView|'s size
UIGraphicsBeginImageContextWithOptions(yourView.frame.size, NO, 0.f);
[targetImage drawInRect:CGRectMake(0.f, 0.f, yourView.frame.size.width, yourView.frame.size.height)];
UIImage * resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[yourView setBackgroundColor:[UIColor colorWithPatternImage:resultImage]];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
30954 次 |
最近记录: |