How can I create a custom styled EntryElement with MonoTouch.dialog?

十年热恋 提交于 2019-12-13 02:19:17

问题


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;
    }
}

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;
    }
}

回答1:


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;
}


来源:https://stackoverflow.com/questions/15666960/how-can-i-create-a-custom-styled-entryelement-with-monotouch-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!