【发布时间】:2011-08-26 08:29:53
【问题描述】:
是否有可能在 Objective-c 中的UITableViewController 中突出显示选定单元格的边框?
【问题讨论】:
标签: iphone objective-c ipad uitableview highlighting
是否有可能在 Objective-c 中的UITableViewController 中突出显示选定单元格的边框?
【问题讨论】:
标签: iphone objective-c ipad uitableview highlighting
您可以尝试使用setSelectedBackgroundView: 制作自定义 UIView/UIImageView 以供选择
这是我在自定义 tableviewcell 中用于自定义渐变的示例代码:
UIView *selctionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = selctionView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blueColor] CGColor], (id)[[UIColor redColor] CGColor], nil];
[selctionView.layer insertSublayer:gradient atIndex:0];
[self setSelectedBackgroundView:selctionView];
编辑:
我发现你也可以使用这些方法:
[test.layer setBorderColor: [[UIColor redColor] CGColor]];
[test.layer setBorderWidth: 1.0];
对于图层。
一定要导入 QuartzCore.h
对于整个 tableview:
[tableViewController.tableView setSeparatorColor:[UIColor redColor]];
【讨论】:
这真的很简单,因为 OS 3.0 只是在 willDisplayCell 方法中设置单元格的背景颜色。不得在 cellForRowAtIndexPath 中设置颜色。
这适用于普通样式和分组样式:
代码:
P.S:这里是 willDisplayCell 的文档摘录:
"A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out."
我在 colionel 的这篇文章中找到了这些信息。谢谢他!
【讨论】: