Reputation: 33
Im using the code
NSArray *buttons = [NSArray arrayWithObjects: self.rollBtn,nil];
for(UIButton *btn in buttons)
{
btn.layer.shadowRadius = 3.0;
btn.layer.shadowOffset = CGSizeMake(-2.0, -3.0);
btn.layer.shadowOpacity = 0.5;
btn.layer.shadowColor = [UIColor blackColor].CGColor;
CAGradientLayer *btnGradient = [CAGradientLayer layer];
btnGradient.frame = btn.bounds;
btnGradient.colors = [NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:102.0f / 255.0f green:102.0f / 255.0f blue:102.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:51.0f / 255.0f green:51.0f / 255.0f blue:51.0f / 255.0f alpha:1.0f] CGColor],
nil];
[btn.layer insertSublayer:btnGradient atIndex:0];
}
But all i get is a button with a drop shadow. I've linked the quartz core library, ive imported it, i've linked the buttons, ive tried using different types of buttons; i'm Stumped. Any Ideas whats going wrong? Thanks in advance.
Upvotes: 0
Views: 510
Reputation: 449
I faced same problem. It seems you are building for iOS6 as I do. I found that Autolayout for storyboards, introduced in iOS6, is causing such problems. Just disable it if you don't use this feature:
Upvotes: 1
Reputation: 69047
I think you could try to remove any previously existing CAGradientLayer
in your button:
for(CALayer* layer in btn.layer.sublayers)
if ([layer isKindOfClass:[CAGradientLayer class]])
[layer removeFromSuperlayer];
and then adding your own.
Upvotes: 0
Reputation: 25144
Did you try setting the locations and the start/end points for your gradient ?
btnGradient.locations = @[@(0.), @(1.)];
btnGradient.startPoint = (CGPoint){0., 0.};
btnGradient.endPoint = (CGPoint){0., 1.};
Upvotes: 0