2016-03-05 91 views
0

你好,我想添加自定義單元格的分隔符爲我UITableView所以在我cllforRowAtIndex委託UITableViewCell中添加自定義視圖加載問題

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier] 
} 

在此之後,我添加自定義UIView我cell.content觀點

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)]; 

    lineView.backgroundColor = [UIColor colorWithRed:61.0/255 green:80.0/255 blue:118.0/255 alpha:1.0]; 
    [cell.contentView addSubview:lineView]; 

但我的問題是,當它第一次加載我的分隔符右側不會去UITableView edg,但是一旦我滾動表,它就會變成全寬。這是爲什麼?我該如何解決這個問題?

回答

0
  1. 創建自定義UITableViewCell

  2. 設置分離器的框架在細胞

或者你也可以更換分離顏色像這樣的layoutSubviews方法,如果是這樣的話:

[self.tableView setSeparatorColor:[UIColor myColor]]; 
+0

或不能改變默認的分色器顏色? – user1960169

+0

你可以,很容易'[self.tableView setSeparatorColor:[UIColor myColor]];' – RaffAl

+0

謝謝改變顏色解決了我的問題 – user1960169