2015-06-07 51 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