MonoTouch中的自定义UIButton颜色
问题描述:
我在使用MonoTouch以编程方式硬编码UIButton
的颜色时遇到了问题。标准的RectRound按钮是白色的,我需要这个按钮是蓝色的。这里是我的代码:MonoTouch中的自定义UIButton颜色
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);
}
非常感谢您的帮助!
答
看一看Is it even possible to change a UIButtons background color?
它解释了为什么,为UIButtonType.RoundedRect
,您将无法更改背景颜色如你所愿。即您需要创建一个Custom
按钮并复制圆角矩形外观。