0

I am trying to develop an app with MonoTouch. For some screens I create the UI in code. I have a dynamically created RadioGroup with normally two to four RadioElements (choices). Sometimes the text (dynamic too) is too long for the RadioElement so that on an iPhone the text gets shorted by ... at the end.

I have googled and found no suggestion on how to create multiline RadioElements. I know you can create a MultilineElement if you want text over several lines, but how would I go about combining the two? I assume I have to inherit from RadioElement and override some events, but which? Is it the MonoTouch.UIKit.UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv) event?

Alternatively, how would you go about creating a MultilineElement that get a check mark on it when it got pressed/selected?

Or should I be thinking completely different? Are there some other components that could solve this in a simpler way?

Halvard
  • 3,891
  • 6
  • 39
  • 51

1 Answers1

0

This is a sort-of solution (at least it solves my problem):

public class MultilineRadioElement : RadioElement
{
    public MultilineRadioElement (string caption, string group) 
      : base(caption, group) { }

    public override MonoTouch.UIKit.UITableViewCell GetCell 
      (MonoTouch.UIKit.UITableView tv)
    {
        var cell = base.GetCell (tv);
        cell.TextLabel.Lines = 2;
        return cell;
    }
}

When I now use a MultilineRadioElement instead of a RadioElement the text shows on two lines. For me two lines are enough. If the text is even longer and you still want to fit it inside the RadioElement at its current size you will probably have to calculate the size of the text and for example set the font in cell.TextLabel.Font to a more appropriate font.

I don't know how to make the RadioElement itself get bigger, so this is my best suggestion.

By the way, you should probably also add

protected override MonoTouch.Foundation.NSString CellKey 
{
    get { return base.CellKey; }
}

to the MultilineRadioElement as the intellisense in my Xamarin Studio suggests that this should be done when overriding GetCell, although it seems to work without it as well.

I am very happy if someone has an even better suggestion!! (yes, two exclamation marks :) )

Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
Halvard
  • 3,891
  • 6
  • 39
  • 51