Shogan
Shogan

Reputation: 1195

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

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

Upvotes: 1

Views: 1889

Answers (1)

NilsH
NilsH

Reputation: 13821

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

Upvotes: 1

Related Questions