2013-03-21 54 views
0

我有类似的问题(UIButton: Add gradient layer and title is not shown anymore - how to fix?),但他的解决方案并不适合我。首先,我对MonoTouch有点新,但从来没有像定制开箱即用的控件一样。我试图给我的按钮添加一个渐变,但是当我这样做时,渐变看起来完全如我所愿,但文本被覆盖(我将渐变的不透明度设置为.5来测试)。我有一个故事板,在其中我可视化地设计了界面,但想调整一些东西。MonoTouch UIButton渐变封面标题

这里是我的代码:

var gradient = new CAGradientLayer(); 
gradient.Frame = getStartedButton.Layer.Bounds; 
gradient.Colors = new MonoTouch.CoreGraphics.CGColor[] 
{ 
    UIColor.FromRGB (23, 55, 94).CGColor, 
    UIColor.FromRGB (33, 81, 141).CGColor 
}; 

getStartedButton.Layer.AddSublayer(gradient); 
getStartedButton.Layer.CornerRadius = 10; 
getStartedButton.Layer.BorderColor = UIColor.White.CGColor; 
getStartedButton.Layer.BorderWidth = 1; 

getStartedButton.VerticalAlignment = UIControlContentVerticalAlignment.Center; 
getStartedButton.Font = UIFont.FromName("Helvetica", 12); 
getStartedButton.SetTitleColor(UIColor.White, UIControlState.Normal); 

getStartedButton.SetTitle("Get Started", UIControlState.Normal); 

回答

1

尴尬,但它只是在XCode中改变按钮的类型定制的问题。