valdetero
valdetero

Reputation: 4652

Can EntryElement be multiline on MonoTouch.Dialog?

I subclassed EntryElement and have set the UILineBreakMode in the GetCell method as such:

public class EntryElementEnhanced : EntryElement, IElementSizing
{
    public EntryElementEnhanced(string caption, string placeholder, string value) : base (caption, placeholder, value) {}


    public float GetHeight(UITableView view, NSIndexPath indexPath)
    {
        return 100.0f; //arbitrary number just for testing
    }

    public override UITableViewCell GetCell (UITableView tv)
    {
        var cell = base.GetCell (tv);
        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
        cell.TextLabel.Lines = 0;


        return cell;
    }
}

This does not seem to make the text that gets entered into the cell word-wrapped. Should I be setting this somewhere else?

If someone knows a better approach, what I'm trying to accomplish at a higher level is I want to create the equivalent of an UITextArea in MonoTouch.Dialog.

Upvotes: 6

Views: 2913

Answers (4)

Dan Morphis
Dan Morphis

Reputation: 1727

I'll throw my hat into the ring. I looked at a couple of the multiline entry element gists out there, and they all had layout issues. I wrote this one https://gist.github.com/akcoder/5723722 to address the layout issues and to also handle orientation changes. This should work on all versions of the iPhone and iPad.

Upvotes: 2

Dave Weaver
Dave Weaver

Reputation: 415

I created a MultilineEntryElement by subclassing UIViewElement at https://gist.github.com/4080025

Works pretty well and handles a placeholder. You will need to update it for your specific width.

Upvotes: 2

Mr W
Mr W

Reputation: 676

there is a multilineEntryElement code piece at https://gist.github.com/315408

in my app it looks a bit funky but it works.

Upvotes: 4

poupou
poupou

Reputation: 43553

EntryElement creates an UITextField which is a one line only control.

If you need multiple lines then I suggest you to create your own Element, e.g. MultilineEntryElement, and have it use a UITextView internally.

You could do this by copy-pasting code from EntryElement or by inheriting from the UIViewElement (or a bit of both).

Upvotes: 5

Related Questions