iOS开发-为UITableViewCell添加横线

在开发过程中经常会遇到设计稿中Cell分割线样式和系统自带的样式差别很大,如何实现这里做下总结,主要包括如下两步:

 

1. 取消TableView默认的分割线样式

_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

 

2. 为TableViewCell添加背景图片

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = (UITableViewCell *)[_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        // 为cell设置背景图片,是一张的上下横线,中间空白的背景图片
        cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage resizedImage:@"exitGroupButton.png"]];
    }
    
    cell.imageView.image = [UIImage imageNamed:@"profile_setting@2x.png"];
    cell.textLabel.text = @"设置";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
exitGroupButton.png:



posted @ 2015-09-07 16:00  feiling  阅读(974)  评论(0编辑  收藏  举报