【问题标题】:Custom UIButton Color in MonoTouchMonoTouch 中的自定义 UIButton 颜色
【发布时间】:2012-08-01 14:35:47
【问题描述】:

我在使用 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);

    }

非常感谢您的帮助!

【问题讨论】:

    标签: c# ios mono xamarin.ios uibutton


    【解决方案1】:

    看看Is it even possible to change a UIButtons background color?

    它解释了为什么对于UIButtonType.RoundedRect,您将无法按预期更改背景颜色。 IE。您需要创建一个Custom 按钮并复制圆角矩形外观。

    【讨论】:

      【解决方案2】:

      我已经在我的 previos anwser 中发布了这个,所以请检查我粘贴的链接 change UIButton Color dynamically

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-17
        • 2018-06-29
        • 2015-09-22
        • 1970-01-01
        相关资源
        最近更新 更多