iphone - 创建类似于所选 UITableViewCell 的 UILabel 背景

标签 iphone cocoa-touch uitableview ios uilabel

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

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

最佳答案

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

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

关于iphone - 创建类似于所选 UITableViewCell 的 UILabel 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4558508/

相关文章:

IOS Flutter 运行 - 未连接设备

iphone - 我怎么知道我的应用程序是否在 iTunes 应用程序商店中有推荐?

objective-c - performSelector 方法有什么作用?

ios - Swift,将更多数据加载到 TableView 中会导致滚动滞后

arrays - Swift 数组不返回所有值

ios - iPhone MKMapView - MKPolygon 问题

iphone - 初始化后更改 NSMutableURLRequest 的 url

iphone - 在 UINavigationBar titleView 中添加 2 个 UILabels

ios - 无法解析基本的 JSON - iOS

ios - 使用 NSUserDefaults (Swift) 在 ViewController 和 TableVC 之间传递数据