iOS开发-为UITableViewCell添加横线

原文地址::https://www.cnblogs.com/feiling/p/4789097.html

相关文章

1、iOS开发中设置UITableViewCell中的分割线顶格显示----https://blog.csdn.net/w15117957952/article/details/76854090

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

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

1

_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

2. 为TableViewCell添加背景图片

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

- (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:@"[email protected]"];

    cell.textLabel.text = @"设置";

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}

1

exitGroupButton.png:

1

<br><br>

发布了136 篇原创文章 · 获赞 306 · 访问量 437万+

猜你喜欢

转载自blog.csdn.net/xqhrs232/article/details/90668591