我无法使用MonoTouch以编程方式对UIButton
的颜色进行硬编码。标准的RectRound按钮是白色的,我需要这个按钮是蓝色的。这是我的代码:
private void CreateButton() {
RectangleF viewFrame = this.subView.Frame;
RectangleF buttonFrame = new RectangleF (10f, viewFrame.Bottom - 200f, viewFrame.Width - 20f, 50f);
this.buttonChangeColor = UIButton.FromType (UIButtonType.RoundedRect);
this.buttonChangeColor.Frame = buttonFrame;
this.buttonChangeColor.SetTitle ("Tap to change view color", UIControlState.Normal);
this.buttonChangeColor.SetTitle ("Changing color...", UIControlState.Highlighted);
this.buttonChangeColor.SetTitleColor (UIColor.Red, UIControlState.Normal);
//This here is my attempt. The rounded rectangle remains white and I can see some blue peeking out from behind but I need the button to be blue, not the background
this.buttonChangeColor.BackgroundColor = UIColor.Blue;
this.buttonChangeColor.TouchUpInside += this.buttonChangeColor_TouchUpInside;
this.subView.AddSubview (this.buttonChangeColor);
}
非常感谢您的帮助!
答案 0 :(得分:2)
查看Is it even possible to change a UIButtons background color?
它解释了为什么,对于UIButtonType.RoundedRect
,您将无法像预期的那样更改背景颜色。即您需要创建一个Custom
按钮并复制圆角直观外观。
答案 1 :(得分:1)
我在之前的帖子中做了这个,所以检查我粘贴的链接 change UIButton Color dynamically