Positioning of Section HeaderView elements in MonoTouch Dialog - xamarin.ios

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

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:

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

Related

Modify the Frame of UIButton

I'm trying to resize a UIButton referenced from xib file.
This is what I've tried without success:
RectangleF frame = actionBtn.Frame;
frame.Width = 140;
actionBtn.Frame = frame;
What am I doing wrong?
You can't modify an existing RectangleF. Try this instead
RectangleF frame = actionBtn.Frame;
actionBtn.Frame = new RectangleF(frame.X, frame.Y, 140, frame.Height);

MonoTouch.Dialog: Change Color of Section

Normally to change the characteristics (Font, color) of a Section in Plain mode we have to create an entire view from scratch.
In cases where a simple change is needed in color/size, is there an easier way to do this?
Here's what I tend to do:
var header = new UILabel(new RectangleF(0, 0, 320, 25)){
Font = UIFont.BoldSystemFontOfSize (22),
TextColor = UIColor.White,
BackgroundColor = SomethingPretty,
Text = "Something"
};
Section secGroup = new Section(header);
This appears to be the simplest way:
var header = new UILabel(new RectangleF(0, 0, 320, 25)){
Font = UIFont.BoldSystemFontOfSize (22),
TextColor = UIColor.White,
BackgroundColor = SomethingPretty,
Text = "Something"
};
Section secGroup = new Section(header);

Relative Layout width/height is not work programmatically?

I want to doing a relative layout programmatically and set android:layout_widht=60 android:layout_height=60.When i doing programmatically it is fill all screen? How can i do that?
my code:`
RelativeLayout relativeLayout=new RelativeLayout(getContext());
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel_btn.height = 60;
rel_btn.width = 60;
relativeLayout.setLayoutParams(rel_btn);
this.setBackgroundResource(com.example.R.drawable.line);`
screen:
btn.getLayoutParams().width = width;
btn.getLayoutParams().height = height;
in fact, just use
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
60, 60);
that's OK. the problem maybe the background pic stretch the button

Incorrect y position for objects inside UIViewController's view

I created programmatically a multi view iphone application.
when adding objects to a view, like a button for example. in position x = 0, y = 0
this results to x = 0, y = 20 in the iphone simulator.
this is the used code :
UIButton *btnGoToStartView = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnGoToStartView.frame = CGRectMake(0, 0, 240, 30);
[btnGoToStartView setTitle:#"Btn Name" forState:UIControlStateNormal];
[btnGoToStartView addTarget:self action:#selector(myBtnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnGoToStartView];
In the other hand, when I'm placing a button using Interface Builder in position x = 0, y = 0 the result is good.
Till now I didn't found the real reason for this vertical shifting.
Thanks in advance for your hints.
Regards.
It's Ok, I found the solution.
It's a problem of the UIView not the control.
in Interface builder, I opened the MainWindow.xib then I modified the attribute Layout in the inspector window.
I checked [wants full screen].
That's all.

Padding in UITextField

Is it possible to set padding inside a UITextField, if so how?
I was also wondering, here you are:
UIView paddingView = new UIView(new CGRect(0, 0, 5, 20));
YourTextField.LeftView = paddingView;
YourTextField.LeftViewMode = UITextFieldViewMode.Always;
You can modify padding size of course by changing values above.
Hope this will help.

Resources