[英]Get UITableView separatorColor from UITableViewCell?
Is there an easy way to get the separatorColor
of the UITableView
of a UITableViewCell
from within -[UITableViewCell initWithStyle:reuseIdentifier:]
? 有没有一种简单的方法来获得
separatorColor
中的UITableView
一个中UITableViewCell
内-[UITableViewCell initWithStyle:reuseIdentifier:]
?
I'm asking because I'm using -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
and want to add a vertical divider to the UITableViewCell
that is the same color as it's tableView
's separatorColor
. 我这么问是因为我使用的是
-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
,并希望垂直分隔添加到UITableViewCell
是相同的颜色,因为它是tableView
的separatorColor
。
As the separator views are managed by the UITableView, UIKit doesn't expose the colour to UITableViewCells. 由于分隔符视图是由UITableView管理的,因此UIKit不会向UITableViewCells公开颜色。 Separator insets are configurable by the cell, however, because only the cell should have knowledge about its layout which might change the insets required.
但是,分隔符插入可由该单元配置,因为只有该单元才应了解其布局,这可能会更改所需的插入。
I'd suggest passing in the colour when configuring your cell, either in -[UITableView tableView:willDisplayCell:forRowAtIndexPath:]
or -[UITableView tableView:cellForRowAtIndexPath:]
我建议在配置单元格时传递颜色,方法是
-[UITableView tableView:willDisplayCell:forRowAtIndexPath:]
或-[UITableView tableView:cellForRowAtIndexPath:]
I don't think there is. 我认为没有。
Although, there is -[UITableViewCell separatorInsets]
. 虽然有
-[UITableViewCell separatorInsets]
。
I'd recommend hard coding tableView.separatorColor
with whatever UIColor
you want and using the same UIColor
in -[UITableViewCell initWithStyle:reuseIdentifier:]
. 我建议使用所需的任何
UIColor
并在-[UITableViewCell initWithStyle:reuseIdentifier:]
使用相同的UIColor
对tableView.separatorColor
进行硬编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.