2012-02-07 95 views
0

我想将UITableViewCell水平划分为两个。如何为UITableView单元设置复合背景颜色?

设置下半部分的颜色为蓝色,上半部分颜色为淡蓝色。

另外的颜色需要的是所选择的小区时,可以颠倒。

我尝试使用CALayer来实现。但没有太多成功。

由于表中包含大量数据,图像的使用会妨碍性能并使用大量内存。

我如何做到这一点?

回答

0

为什么不能用在后台订购了两架UIViews并分配一个不同的背景色为每一个?

0

创建两个UIView对象并将其背景色设置为所需的背景色。使用这两个视图,为单元格的选定状态和正常状态创建背景视图。您可以通过根据单元格框架设置视图的框架来完成此操作。然后,你需要在cellForRowAtIndexPath:设置为UITableViewCell两个属性。

@property(nonatomic, retain) UIView *backgroundView 
@property(nonatomic, retain) UIView *selectedBackgroundView 
0

您应该能够使用单元格的背景视图属性

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;