Programmatically adding a shadow to a UIButton label

edhog picture edhog · Mar 3, 2011 · Viewed 25.1k times · Source

I'm trying to add a 1px black drop shadow to a button label with no luck. I've tried this:self.setTitleShadowOffset = CGSizeMake(0, -1); but I get:

Request for member 'setTitleShadowOffset' in something not a structure or union

Any suggestions would be fantastic thanks!

Answer

fsaint picture fsaint · Mar 3, 2011

The right property is self.titleLabel.shadowOffset:

UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
[b setTitleShadowColor:[UIColor purpleColor] forState:UIControlStateNormal];
b.titleLabel.shadowOffset = CGSizeMake(1.0, 1.0);
[b setTitle:@"Hello, I'm a Button" forState:UIControlStateNormal];
b.frame = CGRectMake(10.0, 10.0,300.0, 40.0);