private static UIView CreateAccessoryViewWithCloseButton(Action <object, EventArgs> onClose) { var accessoryView = new UIView { Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 44), BackgroundColor = UIColor.FromRGB(251, 253, 253) }; var closeButton = new FlatButton(); var closeButtonText = Localize.GetValue("OkButtonText"); closeButton.SetTitle(closeButtonText, UIControlState.Normal); closeButton.TranslatesAutoresizingMaskIntoConstraints = false; FlatButtonStyle.Green.ApplyTo(closeButton); accessoryView.AddSubview(closeButton); var widthOfText = closeButton.GetSizeThatFits(closeButtonText, closeButton.Font).Width; var totalTextPaddingInButton = 30f; closeButton.AddConstraints(new [] { NSLayoutConstraint.Create(closeButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 36f), NSLayoutConstraint.Create(closeButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, widthOfText + totalTextPaddingInButton) }); accessoryView.AddConstraints(new [] { NSLayoutConstraint.Create(closeButton, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, accessoryView, NSLayoutAttribute.Trailing, 1, -8f), NSLayoutConstraint.Create(closeButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, accessoryView, NSLayoutAttribute.CenterY, 1, 0), }); closeButton.TouchUpInside += (sender, e) => onClose(sender, e); return(accessoryView); }