Matthew Ruston
Matthew Ruston

Reputation: 4322

Positioning of Section HeaderView elements in MonoTouch Dialog

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

Upvotes: 0

Views: 880

Answers (2)

Casper Skoubo
Casper Skoubo

Reputation: 310

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

Upvotes: 0

Theos
Theos

Reputation: 666

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

Upvotes: 5

Related Questions