c# - How do you make buttons programmatically using xamarin? -
i'm trying create buttons programmatically using xamarin ide (c#). code need create button, set size, set text, set background color, , set constraints? there way define button 1/4 of width of screen? in advance.
first create button
uibutton button = new uibutton(); cgrect screenbounds = uiscreen.mainscreen.bounds; float buttonwidth = (float)screenbounds.x / 4; button.frame = new cgrect (0f, 0f, buttonwidth, 50f); button.settitle ("title", uicontrolstate.normal); button.backgroundcolor = uicolor.green;
and add subview active view
this.addsubview (button);
and add event touchupinside
button.touchupinside += (object sender, system.eventargs e) => { debug.writeline( "button clicked!"); };
Comments
Post a Comment