2015-06-07 50 views

回答

0

加上一个bacgroundImagecontroller,然后就做出UITableViewCell的背景色泽鲜明,在你CustomViewCell添加UIView白色backgroundColor。调整你的UITableViewSeperatorStyle为零。希望它有效!

1

这只是设置的事情细胞的backgroundView,因为我在这里做的:

enter image description here

这一点,你在你的屏幕截图显示之间有什么区别纯粹的外观细节的问题:在你的屏幕没有灰度梯度,而是白色圆角矩形,白色圆角矩形用阴影绘制,单元高度更高,并且背景视图图像被故意制造得比单元高度短,以便增加表观间距在细胞之间。但这些都是绘图和配置的小事。

+0

您可以在不设置背景的情况下执行此操作,请参阅下面的答案。 – itsProf

+0

@matt我只是为我的单元格添加一个背景视图,并将视图背景颜色设置为绿色,以便我可以看到它,但即使我缩小了视图的框架,它也适合所有的行。任何线索? – VAAA

+0

无论如何,背景视图_itself_会自动调整到单元格的大小。您需要为该视图提供一个子视图,该子视图的大小相对于其超视图而言较小。或者,将其设为图像视图并在中心模式下使用较小的图像。这就是为什么我在我的回答中说过,你让背景视图变小 - 你不能让背景视图变小。 – matt

0

有关背景查看您应该使用:

self.myTableView.backgroundView = bgView; 

那么你应该改变高度:

- (CGFloat)tableView:(UITableView *)tableView 
heightForRowAtIndexPath:(NSIndexPath *)indexPath 

只要把一个int值这里,它代表了你的高度。

对于文本,我建议您将UILabel放在您的单元格上,然后更改其属性以自定义字体,文本大小。

0

假设cell是cellForRowAtIndexPath方法中的表格视图单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseIdentifier"]; 

    cell.contentView.layer.cornerRadius = 10.0; 
    // or whatever you want to set your corner radius 

    return cell; 
} 
0

它很简单。在设计你的自定义单元格时,创建一个UIView,并将它嵌入到各个方面。与此类似。

enter image description here

然后创建UIView的一个属性,像这样:

@property (strong, nonatomic) IBOutlet UIView *cellInsetView; 

确保您在Interface Builder这个勾起来。

然后在您的视图控制器ViewDidLoad方法中,您可以添加以下内容来创建圆角和下方的阴影线。 (我建议创建构建您的自定义视图,让您的viewDidLoad方法清洁方法。)

//Set the corner radius and alpha to cell background 
    self.cellInsetView.layer.cornerRadius = 2; 
    self.cellInsetView.layer.masksToBounds = YES; //Corner Radius 
    [self.cellInsetView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.35]]; 

//create bottom shadow/border 
    CALayer *cellInsetBottomShadow = [CALayer layer]; 

//Place the border according to the cell size  
    cellInsetBottomShadow.frame = CGRectMake(0.0f, self.cellInsetView.frame.size.height-1.0f, self.cellInsetView.frame.size.width-2.0f, 1.0f); 

    cellInsetBottomShadow.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3].CGColor; 

//Add the bottom border/shadow to the cell 
    [self.cellInsetView.layer addSublayer:cellInsetBottomShadow]; 

上面的代码将产生类似下面所示的一个单元格,可以修改圆角半径得到你想要的影响。我在你可能不想要的单元格的背景上设置了一个字母集。

enter image description here