Skip to content

Instantly share code, notes, and snippets.

@johnkors
Created May 9, 2011 17:22
Show Gist options
  • Save johnkors/962916 to your computer and use it in GitHub Desktop.
Save johnkors/962916 to your computer and use it in GitHub Desktop.
En sentrert UIButton i MonoTouch
public UIButton GetCenteredButton()
{
var buttonWidth = 250f;
var center = (window.Frame.Width / 2) - (buttonWidth / 2); //BYTT UT window MED DITT VIEW OM DU ER I EN VIEWCONTROLLER
var position = new RectangleF(center,50f,buttonWidth,100f);
var uiButton = new UIButton(position);
uiButton.BackgroundColor = UIColor.Gray;
var textButtonLabel = new UILabel();
textButtonLabel.Text = "Trykk her";
textButtonLabel.BackgroundColor = UIColor.Red;
uiButton.SetTitle("Trykk her", UIControlState.Normal);
uiButton.TouchUpInside += HandleTouchUpInside;
return uiButton;
}
private void HandleTouchUpInside(object sender, EventArgs e)
{
var button = (UIButton) sender;
button.BackgroundColor = UIColor.Red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment