背景“水印”为 UIViewController 键入图像

发布于 2024-12-27 06:32:36 字数 317 浏览 2 评论 0原文

我正在尝试将图像设置为 uiview 的背景,这是我的做法:

UIImage *bgImage = [UIImage imageNamed:@"watermark.png"];
self.view.layer.contents = bgImage.CGImage;
self.view.backgroundColor = [UIColor clearColor];

这在 iOS5 中有效,但在 iOS4 上我得到的只是黑色背景。有什么想法吗?

我尝试了其他方法,例如 colorWithPatternImage,但这无法正确显示图像。

I'm trying to set an image as the background for a uiview, here's how I do it:

UIImage *bgImage = [UIImage imageNamed:@"watermark.png"];
self.view.layer.contents = bgImage.CGImage;
self.view.backgroundColor = [UIColor clearColor];

This works in iOS5, but on iOS4 all I get is a black background. Any ideas?

I tried other approaches such as colorWithPatternImage, but that doesn't get the image displayed properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只有一腔孤勇 2025-01-03 06:32:36

尝试将第二行修改为:

self.view.layer.contents = (id)bgImage.CGImage;

Try modifying the second line to this:

self.view.layer.contents = (id)bgImage.CGImage;
云朵有点甜 2025-01-03 06:32:36

你可以试试这个。

UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image.png"]];
[self.view addSubview:backgroundImage];
[self.view sendSubviewToBack:backgroundImage];
[backgroundImage release];

在这种情况下,您可以管理视图层次结构并将 UIImageView 放在当前视图下。希望有帮助。

You could try this.

UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image.png"]];
[self.view addSubview:backgroundImage];
[self.view sendSubviewToBack:backgroundImage];
[backgroundImage release];

In this case you can manage the view hierachy and put the UIImageView under the current view. Hope it helps.

铜锣湾横着走 2025-01-03 06:32:36

我认为一切都很好,只需将其用于您的单元格cellForAtIndexpath

 UIImage *bgImage = [UIImage imageNamed:@"watermark.png"];
 UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
 [cell.contentView addSubview: imageView];

I think everything is nice and OK, just use this for your cell cellForAtIndexpath

 UIImage *bgImage = [UIImage imageNamed:@"watermark.png"];
 UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
 [cell.contentView addSubview: imageView];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文