+(void)roundCorners:(UIRectCorner)corners forView:(UIView *)view { UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(10.0, 10.0)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = view.bounds; maskLayer.path = maskPath.CGPath; view.layer.mask = maskLayer; } +(void)roundCornersForSelectedBackgroundViewForTableView:(UITableView *)tableView cell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath { NSUInteger rows = [tableView numberOfRowsInSection:indexPath.section]; if (rows == 1) { [[self class] roundCorners:UIRectCornerAllCorners forView:cell.selectedBackgroundView]; } else if (indexPath.row == 0) { [[self class] roundCorners:UIRectCornerTopLeft | UIRectCornerTopRight forView:cell.selectedBackgroundView]; } else if (indexPath.row == rows-1) { [[self class] roundCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight forView:cell.selectedBackgroundView]; } else { [[self class] roundCorners:0 forView:cell.selectedBackgroundView]; } } +(void)deferredRoundCornersForSelectedBackgroundViewForTableView:(UITableView *)tableView cell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath { int64_t delayInSeconds = 0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [[self class] roundCornersForSelectedBackgroundViewForTableView:tableView cell:cell indexPath:indexPath]; }); } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { // cell.selectedBackgroundView.frame is not sized correctly yet, so rounding the corners has to be deferred briefly [[self class] deferredRoundCornersForSelectedBackgroundViewForTableView:tableView cell:cell indexPath:indexPath]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* identifityString = @"cell"; YQOptionTableViewCell* cell = (YQOptionTableViewCell*)[tableView dequeueReusableCellWithIdentifier:identifityString]; if(!cell) { cell = [[[YQOptionTableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:identifityString] autorelease]; cell.selectedBackgroundView = [[UIView alloc]initWithFrame:cell.frame]; cell.selectedBackgroundView.backgroundColor = [UIColor redColor]; }
相关推荐
- 默认的选中效果是灰色背景,通过`cell.selectedBackgroundView`可以替换为自定义的背景视图。 - 使用`cell.selectionStyle`设置选中样式,如None、Blue、Gray。 6. **Indicator样式** - 编辑指示器(Edit ...
- 使用`UITableViewStyle`枚举来设置表格样式,例如`UITableViewStylePlain`或`UITableViewStyleGrouped`。 - 在`UITableViewController`或`UIViewController`中初始化`UITableView`时,可以指定样式。 2. **...
3. 表视图样式:虽然默认的UITableViewStylePlain适合列表形式,但为了实现网格效果,我们可能需要使用`UITableViewStyleGrouped`,然后通过自定义布局来达到网格的目的。 4. 自定义FlowLayout:如果需要更高级的...
表视图有两种主要类型:普通表视图(UITableViewStylePlain)和分组表视图(UITableViewStyleGrouped)。普通表视图显示连续的行,而分组表视图将数据分段,每个段头有自己的标题,使内容更有组织性。 在本教程中,...
默认UITableView是UITableViewStyleGrouped组模式,Frame是self.view.bounds的大小,继承者可重写setBaseTableView方法修改TableView和添加tableHeaderView和tableFooterView等属性! 内部提供可以跳转Model和基本...
首先,UITableView有两种基本样式:分组样式(UITableViewStylePlain)和无分组样式(UITableViewStyleGrouped)。分组样式将数据分为多个视觉上独立的段落,每个段落有自己的头部和尾部,适合呈现有结构的数据;而...
1. **创建自定义类**:继承自 `UITableViewCell` 类并添加自定义视图元素。 2. **注册cell类**:在 `viewDidLoad` 或 `viewWillAppear` 中调用 `tableView.register` 方法。 3. **重写`cellForRowAtIndexPath`方法**...
`tableView:cellForRowAtIndexPath:` 方法是另一个关键代理方法,用于返回指定索引路径下的单元格。在该方法中,你可以自定义单元格的内容,如文本、图像等。 接下来是单元格的具体内容。在iOS中,单元格...
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; self.tableView.dataSource = self; self.tableView.delegate = self; // 添加其他配置,如注册单元格...
1. **初始化与配置**: 创建分组表格视图时,需设置其样式为`UITableViewStyleGrouped`。你可以自定义表格视图的组头和组尾,以及每个单元格的样式。 2. **数据源协议**: 实现`UITableViewDataSource`协议,提供数据...
IOS UITableView和UITableViewCell的几种样式详细介绍 今天要分享的是IOS开发中一个使用率非常高的一个控件——-UITableView,这两天正在使用tableview做信息的显示,在写代码时对...2.UITableViewStyleGrouped:
本示例“IOS TableView Grouped”主要关注的是分组表格视图(UITableViewStyleGrouped),它以清晰的分组形式展示数据,使用户界面更加整洁、易于阅读。 分组表格视图的特点是将数据分成多个段落或组,每个组有自己...
MCtableView *tableView = [MCtableView mcDefaultMCTableViewVC:self CGFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) TableViewStyle:UITableViewStyleGrouped];...
2. **分组类型 (`UITableViewStyleGrouped`)**:这种样式常用于配置界面或者联系人列表界面,它通过分组的形式来组织数据,使得数据结构更加清晰易懂。每个分组之间会有一定的间隔,方便用户区分不同的数据集合。 ...
- `UITableViewStyleGrouped`: 此样式将数据分组,每个组有自己的头部和底部视图。 2. **设置数据源和委托**: UITableViewDataSource和UITableViewDelegate是UITableView的核心协议,它们定义了如何填充表格和处理...
首先,UITableView有两种基本样式:UITableViewStylePlain和UITableViewStyleGrouped。前者不区分组,显示为连续的行;后者将数据分组,每个组有自己的头部和可能的尾部。UITableView的每一行由UITableViewCell表示...
这里,我们设置了默认的表格样式为UITableViewStylePlain,也可以选择UITableViewStyleGrouped来创建分组的表格。同时,通过覆盖父类的初始化方法,确保不论使用哪个初始化方法,最终都会使用我们设定的风格。 在...
- 表视图有两种样式:普通样式(UITableViewStylePlain)和分组样式(UITableViewStyleGrouped)。 2. **数据源(DataSource)**: - 数据源对象是UITableViewDelegate和UITableViewDataSource协议的实现者,负责...