Benny
Benny

Reputation: 3917

MonoTouch UIButton Gradient Covers Title

I have a similar problem to this post (UIButton: Add gradient layer and title is not shown anymore - how to fix?) but his solution did not work for me. First things first, I'm somewhat new to MonoTouch, but have never gone as far as customizing the out of the box controls.

I am trying to add a gradient to my button, but when I do so, the gradient looks exactly as I want, but the text is covered (I set the opacity of my gradient to .5 to test). I have a storyboard in which I have visually designed the interface, but want to tweak a few things.

Here is my code:

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);

Upvotes: 0

Views: 865

Answers (1)

Benny
Benny

Reputation: 3917

Embarrassing, but it was simply a matter of changing the type of button to custom in XCode.

Upvotes: 1

Related Questions