Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UITableView中高亮显示选定单元格的边框_Iphone_Objective C_Ipad_Uitableview_Highlighting - Fatal编程技术网

Iphone 在UITableView中高亮显示选定单元格的边框

Iphone 在UITableView中高亮显示选定单元格的边框,iphone,objective-c,ipad,uitableview,highlighting,Iphone,Objective C,Ipad,Uitableview,Highlighting,是否有可能在Objective-c中的UITableViewController中突出显示所选单元格的边框 下面是我在自定义tableviewcell中用于自定义渐变的示例代码: UIView *selctionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)] autorelease]; CAGradientLayer *gradien

是否有可能在Objective-c中的
UITableViewController
中突出显示所选单元格的边框

下面是我在自定义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]];

这非常简单,因为OS3.0只需在willDisplayCell方法中设置单元格的背景色。不能在cellForRowAtIndexPath中设置颜色

这适用于普通样式和分组样式:

代码:

  • (void)tableView:(UITableView*)tableView将显示单元格:(UITableViewCell*)用于rowatindexpath的单元格:(NSIndexPath*)indexPath{ cell.backgroundColor=[UIColor redColor]; }
备注:这里是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."

我在科里奥尼尔的这篇文章中找到了这些信息。谢谢他

嘿,谢谢。这是我的实际需求:我使用的是splitviewcontroller。在这种情况下,当我在rootviewcontroller中选择一个特定的单元格时,相应单元格的4个侧边框颜色需要更改。没问题,您也可以在select上制作一个动画(例如将渐变从“暗到亮”更改为“亮到暗”),看起来非常棒,我只是在被选中时再次选择它时出现了一些错误。是的,这确实很有效。如何在不影响其他单元格的情况下更改所选单元格的文本颜色?我想您必须在“DidSelectRowatineXpath:”方法中更改颜色。再次执行另一个查询。如何设置高亮显示单元格的右侧和左侧边框颜色?