在Monotouch中设置真实的背景颜色

时间:2013-03-20 04:44:16

标签: c# iphone ios xamarin.ios

好的,我正在这样做:

    UIButton btReturn;

    btReturn = UIButton.FromType (UIButtonType.RoundedRect);

    btReturn.Frame = btnBounds;
    btReturn.SetTitle (Caption, UIControlState.Normal);

    btReturn.Layer.CornerRadius = 14;
    btReturn.ClipsToBounds = true;
    btReturn.TouchUpInside += touchHandler;
    btReturn.BackgroundColor = UIColor.FromRGB (0xe4, 0x96, 0x37);
    return btReturn;

这引出了一个问题......为什么它会变成白色背景?我最初尝试将其设置为使用背景图像清除,但这也不起作用......

可能出现什么问题?

3 个答案:

答案 0 :(得分:1)

这是因为RoundedRect类型UIButton类型不允许除白色之外的任何其他颜色背景。

你必须使用UIButtonType.Custom来改变背景颜色(但是你会丢失漂亮的圆形按钮并最终得到一个方形按钮 - 你必须设计自己喜欢的按钮你最喜欢的图形包:)

答案 1 :(得分:0)

试试这个,

         btReturn.BackgroundView = null;
         btReturn.BackgroundColor = UIColor.Black;

另请参阅以下链接

How to change background color of UIButton in Monotouch

How to set the background color on a DialogViewController (Monotouch.Dialog)

答案 2 :(得分:0)

请看这里:is-it-even-possible-to-change-a-uibuttons-background-color还有一个示例,以及如何创建自己的按钮,因为您无法修改圆角按钮。

相关问题