创建与选定的 UITableViewCell 类似的 UILabel 背景

发布于 2024-10-10 00:00:29 字数 251 浏览 4 评论 0原文

我想创建一个 UILabel 并将其背景设置为渐变蓝色,就像选定的 UITableViewCell 一样。我怀疑我需要使用 UIColor colorWithPatternImage:。如果是,我不确定获取图案图像的最佳方法是什么。或者,关于如何实现这一目标还有其他建议吗?

我不想创建预渲染的背景图像,因为我需要它在 iPhone 3GS、4 和 iPad 上工作,它们都需要不同的背景图像。

I want to create a UILabel and set its background to the gradient-blue like a selected UITableViewCell. I suspect I need to use UIColor colorWithPatternImage:. If yes, I am not sure what the best way to get the pattern image is. Or, any other suggestions on how to accomplish this?

I would prefer not to create a pre-rendered background image since I need this to work on iPhone 3GS, 4 and iPad which all will require different background images.

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

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

发布评论

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

评论(4

热鲨 2024-10-17 00:00:29

Apple 使用的图像是 UITableSelection.png。我已附上标准图像和@2x 图像。

UIView *selectedView = [[UIView alloc] initWithFrame:self.bounds];
selectedView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"UITableSelection.png"]];
cell.selectedBackgroundView = selectedView;

在此处输入图像描述
在此处输入图像描述

The image used by Apple is UITableSelection.png. I have attached the standard and @2x images.

UIView *selectedView = [[UIView alloc] initWithFrame:self.bounds];
selectedView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"UITableSelection.png"]];
cell.selectedBackgroundView = selectedView;

enter image description here
enter image description here

梦巷 2024-10-17 00:00:29

这是一种未记录的颜色,我不确定您是否想使用未记录的颜色。但它被称为

[UI颜色表选择颜色]

另外,它没有您想要的渐变效果。我认为这是应用于单元格的渐变叠加?我不知道苹果是怎么做到的,但如果你想知道颜色,那就是它。 RGB 值分别为 0.16、0.43、0.83。

It's an undocumented color, I'm not sure if you'd want to use an undocumented color. But it's called

[UIColor tableSelectionColor]

Also, it doesn't have the gradient effects that you want. I assume it's a gradient overlay applied to the cell? I don't know how apple does it, but if you wanted to know the color, that's what it is. the RGB values are 0.16, 0.43, 0.83 respectively.

一场春暖 2024-10-17 00:00:29
Your_label_name.backgroundColor = [UIColor colorWithRed:72.0/255.0 green:118.0/255.0 blue:255.0/255.0 alpha:1.0];

另请参阅此链接:
http://cloford.com/resources/colours/500col.htm

Your_label_name.backgroundColor = [UIColor colorWithRed:72.0/255.0 green:118.0/255.0 blue:255.0/255.0 alpha:1.0];

also refer this link :
http://cloford.com/resources/colours/500col.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文