【发布时间】:2012-02-07 07:38:32
【问题描述】:
我想将UITableViewCell 水平分成两部分。
将下半部分颜色设置为蓝色,将上半部分颜色设置为浅蓝色。
选择单元格时颜色也需要反转。
我尝试使用CALayer 来实现。但不太成功。
由于表格包含大量数据,因此使用图像会影响性能并占用大量内存。
我该怎么做?
【问题讨论】:
标签: iphone uitableview calayer background-color
我想将UITableViewCell 水平分成两部分。
将下半部分颜色设置为蓝色,将上半部分颜色设置为浅蓝色。
选择单元格时颜色也需要反转。
我尝试使用CALayer 来实现。但不太成功。
由于表格包含大量数据,因此使用图像会影响性能并占用大量内存。
我该怎么做?
【问题讨论】:
标签: iphone uitableview calayer background-color
为什么不使用两个在后台排序的 UIView,并为每个 UIView 分配不同的背景颜色?
【讨论】:
创建两个UIView 对象并将其背景颜色设置为所需的颜色。使用这两个视图,为单元格的选定状态和正常状态创建背景视图。为此,您可以根据单元格的框架设置视图的框架。然后,您需要为cellForRowAtIndexPath: 中的UITableViewCell 设置两个属性。
@property(nonatomic, retain) UIView *backgroundView
@property(nonatomic, retain) UIView *selectedBackgroundView
【讨论】:
你应该可以使用单元格的背景视图属性
UITableViewCell *cell = // ... code to create table view cell
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.frame.size.width, cell.contentView.frame.size.height/2);
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.frame.size.width, cell.contentView.frame.size.height/2);
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.frame.size.height, cell.contentView.frame.size.width);
[backgroundView addSubview:topView];
[backgroundView addSubview:bottomView];
cell.backgroundView = backgroundView;
【讨论】: