真正在MonoTouch的
问题描述:
好设置背景颜色,我这样做:真正在MonoTouch的
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;
这引出了一个问题...为什么它到底在拿出的白色背景???我本来试图设置清除背景图像,但这也不起作用...
什么可能是错的?
答
这是因为RoundedRect
类型的UIButton
不允许其他任何除白色的颜色背景。
您必须使用UIButtonType.Custom
才能更改背景颜色(但您会失去漂亮的圆角按钮并最终得到一个方形按钮 - 您必须在自己喜欢的图形中设计自己喜欢的按钮包:) :)
答
尝试这样,
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)
令人惊叹......真的让人惊叹......所以,如果我创建一个图像使用圆形,我应该使背景透明,然后设置为自定义? – 2013-03-20 16:21:27
看似可以工作。 – 2013-03-20 19:37:19