This is probably a really basic post but as I am a still learning the MonoTouch Framework and I couldn’t find anywhere on the Internet explaining how to do it. Anyway today I was trying to programmatically create a UIButton in MonoTouch and set the button type.
There is a ButtonType property on the instantiated UIButton object but its read only and I couldn’t see any constructor that took a buttontype.
In the end the answer was quite simple there is a static factory method on the UIButton class that you use to instantiate a new button. The code looks something like this.
1: var button = UIButton.FromType(UIButtonType.RoundedRect);
2: button.frame = new RectangleF(100f, 100f, 100f, 100f);
3: button.SetTitle("click me", UIControlState.Normal);
Tags: IPad, IPhone, MonoDevelop, MonoTouch
[...] This post was mentioned on Twitter by . said: [...]
Nice one, however maybe no sample existed as it is a simple conversion from Objective C. That is the excellent stuff of Monotouch, that it is 1 to 1 mapping to Cocoa Touch API.
I was looking for this the other day as well.
Thanks!
I agree the solution is very simple it is a simple conversion and I was being dumb
Nice one, just what I was after.