Ios 如何在UITableView中更改选定项的分隔色
我有下面的视图Ios 如何在UITableView中更改选定项的分隔色,ios,uitableview,xamarin,Ios,Uitableview,Xamarin,我有下面的视图 _navigationList = new UITableView { Source = UINavigationTableViewSource, BackgroundColor = UIColor.FromRGB(43, 43, 43), // #2b2b2b - same as Android SeparatorColor = UIColor.FromRGB(27,27,27), // #1b1b1b - same as
_navigationList = new UITableView
{
Source = UINavigationTableViewSource,
BackgroundColor = UIColor.FromRGB(43, 43, 43), // #2b2b2b - same as Android
SeparatorColor = UIColor.FromRGB(27,27,27), // #1b1b1b - same as Android
SeparatorInset = UIEdgeInsets.Zero,
ScrollEnabled = true
};
UINavigationTableViewSource
正在使用自定义的UITableViewCell
public sealed class UINavigationTableViewCell : UITableViewCell
{
public new readonly UILabel TextLabel;
public UINavigationTableViewCell(string cellId)
: base(UITableViewCellStyle.Default, cellId)
{
TextLabel = new UILabel(new RectangleF(10, 0, Bounds.Width, 40)) {TextColor = UIColor.White}; // properly position the label.
SeparatorInset = UIEdgeInsets.Zero; // make the boarder go all the way across the list item
ContentView.BackgroundColor = UIColor.FromRGB(43, 43, 43); // #2b2b2b - same as Android
var activeOrb = new UIImageView(new RectangleF(0,0,10,Bounds.Height))
{
Image = UIImage.FromBundle("Images/active_orb.png"),
ContentMode = UIViewContentMode.ScaleAspectFit
};
SelectedBackgroundView = new UIView { BackgroundColor = UIColor.FromRGB(43, 43, 43) };
SelectedBackgroundView.Add(activeOrb);
ContentView.Add(TextLabel);
}
}
除了选定行上丑陋的白线外,所有内容都符合我们的要求
选择行时如何更改分隔颜色?
我从未在xamarin中编程,但我使用的是ios(5-7)sdk。
我建议您不要使用任何分隔符。而是将分隔符行作为
视图添加到单元格中(height-1pixel;width-cellWidth)
由ChaseFlorell编辑-工作示例
存在一些与分隔符和选择相关的iOS 7错误。如果搜索堆栈溢出,您会发现许多建议的解决方法。在我看来,最好的方法是将分隔符样式设置为“无”,然后自己绘制分隔符作为每个单元格的背景。这正是我最终要做的。我想可以,但伙计。。。我自己的代码中的错误很难处理,而不必处理平台中的错误:/Welcome to the real world。我对您的答案进行了快速编辑,以显示一个工作示例。谢谢你的提示!
_navigationList = new UITableView
{
Source = UINavigationTableViewSource,
BackgroundColor = UIColor.FromRGB(43, 43, 43), // #2b2b2b - same as Android
SeparatorStyle = UITableViewCellSeparatorStyle.None,
ScrollEnabled = true
};
Add(_navigationList);
public sealed class UINavigationTableViewCell : UITableViewCell
{
public new readonly UILabel TextLabel;
public UINavigationTableViewCell(string cellId) : base(UITableViewCellStyle.Default, cellId)
{
// The default state
TextLabel = new UILabel(new RectangleF(10, 0, Bounds.Width, 40)) { TextColor = UIColor.White }; // properly position the label.
ContentView.BackgroundColor = UIColor.FromRGB(43, 43, 43); // #2b2b2b - same as Android
ContentView.Add(Separator(Bounds));
ContentView.Add(TextLabel);
// todo: move colors to a config file.
// The selected state
var activeOrb = new UIImageView(new RectangleF(0, 0, 10, Bounds.Height))
{
Image = UIImage.FromBundle("Images/active_orb.png"),
ContentMode = UIViewContentMode.ScaleAspectFit
};
SelectedBackgroundView = new UIView { BackgroundColor = UIColor.FromRGB(43, 43, 43) };
SelectedBackgroundView.Add(Separator(Bounds));
SelectedBackgroundView.Add(activeOrb);
}
private static UIView Separator(RectangleF bounds)
{
return new UIView(new RectangleF(0, 0, bounds.Width, 1))
{
BackgroundColor = UIColor.FromRGB(27, 27, 27)
};
}
}