如何使用 MonoTouch.dialog 创建自定义样式的 EntryElement? [英] How can I create a custom styled EntryElement with MonoTouch.dialog?
问题描述
我正在尝试使用 monotouch.dialog 创建自定义条目元素.我了解如何将 StringElement 子类化以设置我自己的字符串元素的样式 - 请参见下面的示例:
I am trying to create a custom entry element using monotouch.dialog. I understand how to subclass a StringElement to style my own string elements - see example below:
public class CustomStyledStringElementPlain : MonoTouch.Dialog.StyledStringElement
{
public CustomStyledStringElementPlain (string _caption, UIColor _backgroundcolour, UITextAlignment _alignment) : base(string.Empty,string.Empty)
{
TextColor = UIColor.White;
Font = UIFont.FromName ("Helvetica-Bold", 14f);
Caption = _caption;
Alignment = _alignment;
BackgroundColor = _backgroundcolour;
}
}
但是,当对 EntryElement 进行子类化时,例如,我无法访问 BackgroundColor 的属性(这是我想要更改的主要内容!)这是我目前所拥有的...任何关于如何我的指示或建议可以更改背景颜色或其他样式条目元素将不胜感激!
However, when subclassing EntryElement, I am not able to access properties for the BackgroundColor for example (which is the main thing I want to change!) Here is what I have so far... Any pointers or advice on how I could change the background color or otherwise style entry elements would be much appreciated!
public class CustomStyledEntryElementPlain : MonoTouch.Dialog.EntryElement
{
public CustomStyledEntryElementPlain (string _caption, UIColor _colour, UITextAlignment _alignment) : base(string.Empty,string.Empty)
{
ReturnKeyType = UIReturnKeyType.Done;
Caption = _caption;
}
}
推荐答案
要自定义 MonoTouch.Dialog 元素,您可以覆盖 GetCell 方法并在单元格对象上设置所需的外观.像这样:
To customize a MonoTouch.Dialog Element, you can override the GetCell method and set the appearance you want on the cell object. Something like this:
public override UITableViewCell GetCell(UITableView tableView) {
var cell = base.GetCell(tableView);
cell.BackgroundColor = _colour;
return cell;
}
这篇关于如何使用 MonoTouch.dialog 创建自定义样式的 EntryElement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!