3

I am trying to create an inner shadow to create a sense of depth for my UIButton.

I tried the following code, but it doesnt create a shadow if i set a background color. If I set the background color to clear color then it displays a sort of shadow. but i cant control the strenght more than upping the shadoOpacity to 1.

_selectRoutineBtn.layer.masksToBounds = YES;
_selectRoutineBtn.layer.cornerRadius = 8; // if you like rounded corners
_selectRoutineBtn.layer.shadowOffset = CGSizeMake(11, 11);
_selectRoutineBtn.layer.shadowRadius = 2;
_selectRoutineBtn.layer.shadowOpacity = 0.5;
[_selectRoutineBtn.layer setBorderWidth: 1.0f ];

I attempted to use this which was used in another post but I dont know how to implement that.

Could anyone tell me how could i implement that file into my UIButton (I tried putting it in the IB as the class but doesnt do anything) to create the inner shadow or any other solution that i could use to create inner shadow?

enter image description here

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Jonathan Thurft
  • 4,087
  • 7
  • 47
  • 78
  • what do you mean by inner shadow, is it the text shadow or smt else? The default behavior is as you said with solid background it will create shadow around the button. Maybe you can try accessing the layer of titleLabel inside the button with: `_selectRoutineBtn.titleLabel.layer` and add shadow to it – guenis May 10 '13 at 18:53
  • No text shadow. I want basically to add a depth effect into my button. Thus, I need inner shadow around my border to create a sense of depth – Jonathan Thurft May 10 '13 at 18:59
  • You should look into Core Graphics again. The link you provided does the right thing, you just need to try again. – David Rönnqvist May 10 '13 at 19:59
  • Are you trying to create a button that appears concave instead of convex? I.e. buttons usually have a gradient effect that makes them appear to be slightly raised from the surface of the screen. Are you instead trying to make this button appear to be slightly depressed? – MusiGenesis May 10 '13 at 20:06
  • @DavidRönnqvist how do I make the link work? – Jonathan Thurft May 10 '13 at 22:14
  • @MusiGenesis Yes, I am trying to make it look depressed. – Jonathan Thurft May 10 '13 at 22:15
  • @JonathanThurft: then draw it with an emo haircut, or check out my answer below. :) – MusiGenesis May 11 '13 at 18:16
  • Try [this person's method](http://stackoverflow.com/a/12969741/14606). It appears to draw the shadow on a secondary view and then drop it into the main view; this should work for your button as well. – MusiGenesis May 11 '13 at 18:15

0 Answers0