好的,我要这样做:
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;
这就引出了一个问题…为什么它的背景是白色的?我最初试图将其设置为清除背景图像,但这也不起作用…
怎么了?
这是因为UIButton
的RoundedRect
类型不允许除了白色以外的任何其他颜色的背景。
你必须使用UIButtonType.Custom
来改变背景颜色(但你会失去漂亮的圆角按钮,并以一个方形按钮结束-你必须在你最喜欢的图形包中设计你自己的花哨按钮:)
试一下,
btReturn.BackgroundView = null;
btReturn.BackgroundColor = UIColor.Black;
也可参考以下链接,
如何在Monotouch中改变UIButton的背景颜色
如何设置DialogViewController (Monotouch.Dialog)的背景色
看这里:is-it-even-possible-to-change-a-uibuttons-background-color这里也有一个关于如何创建自己的按钮的例子,因为你不能修改圆角按钮