iOS中 UITableViewCell cell划线那些事 韩俊强的博客

简介: 每日更新关注:http://weibo.com/hanjunqiang  在开发中经常遇到cell分割线显示不全或者想自定义线的宽高等; 最近总结了一下,希望帮到大家: 1.不想划线怎么办? TableView.

每日更新关注:http://weibo.com/hanjunqiang 

在开发中经常遇到cell分割线显示不全或者想自定义线的宽高等; 最近总结了一下,希望帮到大家:

1.不想划线怎么办?

TableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; // 设置系统默认线的样式
-(void)viewDidLayoutSubviews {

    if ([TableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [TableView setSeparatorInset:UIEdgeInsetsZero];

    }
    if ([TableView respondsToSelector:@selector(setLayoutMargins:)])  {
        [TableView setLayoutMargins:UIEdgeInsetsZero];
    }

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
每日更新关注:http://weibo.com/hanjunqiang 
2.想划线设置怎么办?

 TableView.separatorStyle = UITableViewCellSeparatorStyleNone;  // 丢掉系统的线,画自定义的线
#define SINGLE_LINE_HEIGHT  (1/[UIScreen mainScreen].scale)  // 线的高度
#define  COLOR_LINE_GRAY [UIColor colorWithRed:224/255.0f green:224/255.0f blue:224/255.0f alpha:1]  //分割线颜色 #e0e0e0
在自定义cell里写入:
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    //下分割线
    CGContextSetStrokeColorWithColor(context, COLOR_LINE_GRAY.CGColor); //  COLOR_LINE_GRAY 为线的颜色
    CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, SINGLE_LINE_HEIGHT)); //SINGLE_LINE_HEIGHT 为线的高度
}
每日更新关注:http://weibo.com/hanjunqiang 

iOS开发者交流QQ群446310206  有问题或技术交流可以咨询!欢迎加入




目录
相关文章
|
26天前
|
数据采集 网络协议 开发工具
如何进行iOS技术博客的备案?
如何进行iOS技术博客的备案?
23 2
|
4月前
|
网络安全 开发者 iOS开发
iOS技术博客:App备案指南
本文介绍了移动应用程序(App)备案的重要性和流程。备案是规范App开发和运营的必要手段,有助于保护用户权益、维护网络安全和社会秩序。为了帮助开发者更好地了解备案流程,本文提供了一份最新、最全、最详的备案指南,包括备案目的、好处、对象、时间、流程、条件和注意事项等内容。
iOS技术博客:App备案指南
|
5月前
|
数据采集 网络协议 开发工具
 如何进行iOS技术博客的备案?
在本篇问答中,我们将为iOS技术博主介绍如何进行备案。如果你的iOS应用只包含简单的页面,并通过蓝牙进行数据采集和传输,那么你可能不需要备案。然而,如果你希望通过域名调用后端服务,建议进行备案以满足国内服务器访问的要求。我们将详细解释备案的三要素以及备案流程,并提供参考资料供你查阅。
|
iOS开发
iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)
iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)
265 0
|
JSON iOS开发 数据格式
iOS开发-图文混排之cell自适应
iOS开发-图文混排之cell自适应
73 0
iOS开发-图文混排之cell自适应
|
iOS开发 开发者
iOS开发-简述UITableView中cell的重用问题
iOS开发-简述UITableView中cell的重用问题
159 0
|
iOS开发
iOS UITableViewCell嵌套CollectionView,tableview和collectionview同时滑动bug修复
iOS UITableViewCell嵌套CollectionView,tableview和collectionview同时滑动bug修复
907 0
|
Web App开发 Dart 安全
flutter制作博客展示平台,现已支持 Web、macOS 应用、Android 和 iOS
Flutter Blog Theme using Flutter | Web, macOS, Android, iOS Flutter 最近发布了 Flutter V2.5.1,其性能得到了很大提升,支持 Web、macOS、Android 和 iOS。 这就是为什么今天我们使用在 Web、macOS 应用、Android 和 iOS 应用上运行的 flutter 创建响应式博客主题。 此外,我们创建了一个具有自定义悬停动画的动画网络菜单。 最后,您将学习如何使用 Flutter 制作响应式应用程序。
325 0
flutter制作博客展示平台,现已支持 Web、macOS 应用、Android 和 iOS
|
iOS开发 开发者
iOS开发中UITableViewCell点击时子视图背景透明的解决方法
iOS开发中UITableViewCell点击时子视图背景透明的解决方法
176 0
iOS开发中UITableViewCell点击时子视图背景透明的解决方法
|
iOS开发
iOS UITableViewCell使用详解
iOS UITableViewCell使用详解
297 0