0

I am trying to customize the position of text in Section element headers in MonoTouch Dialog. I read up on how you are supposed to create you own UILabel to create styled text and then assign that to the HeaderView of the Section object. That part works great.

The problem that I am faced with now is: how can I get a similar text offset as the offset used in the default unstyled Section element (see comparison in attached image). I cannot seem to find a way to get the "Styled Section" text moved away from the left edge of the screen no matter what I do. I tried changing the x coordinate specified in the RectangleF declaration, but whatever I specify appears to be disregarded when the view is rendered.

Here is the backing code for the screenshot:

Root = new RootElement ("Login2Screen");
var labelHeader = new UILabel();
labelHeader = new UILabel(new RectangleF(0, 0, 320, 48));
labelHeader.Text = "Styled 
labelHeader.TextColor = UIColor.Blue;
labelHeader.BackgroundColor = UIColor.Clear;

var styledSection = new Section(labelHeader);
styledSection.Add(new EntryElement("Username", string.Empty, string.Empty));
styledSection.Add(new EntryElement("Password", string.Empty, string.Empty));
Root.Add(styledSection);

var defaultStyleSection = new Section("Default Section");
Root.Add (defaultStyleSection);

enter image description here

2 Answers 2

5
+50

Add the labelHeader into an UIView and then set the x-coordinate of your UILabel to 10.

var viewLabelHeader = new UIView(new RectangleF(0, 0, 320, 48));
var labelHeader = new UILabel(new RectangleF(10, 0, 320, 48));
labelHeader.Text = "Styled section";
labelHeader.TextColor = UIColor.Blue;
labelHeader.BackgroundColor = UIColor.Clear;
viewLabelHeader.AddSubview (labelHeader);

var styledSection = new Section(viewLabelHeader);

Result:

enter image description here

1
  • Well that works! Anyone have reasoning on why this works? Mar 24, 2013 at 1:47
0

Haven't read anything about the position of text in Section element, but

labelHeader = new UILabel(new RectangleF(0, 0, 320, 48));

You are positioning it at 0,0? if you make it 10,0 it should move. i.e. move x position to 10

labelHeader = new UILabel(new RectangleF(10, 0, 320, 48));
1
  • I tried that. The x-coordinate seems to be disregarded when set in the RectangleF in all of my tests. Mar 20, 2013 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.