How can I remove a shadow in iPhone

2019-03-19 23:24发布

问题:

I am using the standard way of making shadows from a button programmatically, but I would like to shadow to no longer exist after I am done with the button. I could set opacity to 0, but would the shadow still exist and if so would it still tax the system. thanks

this gives an error

tempButton.superview.layer.shadowOffset = nil;
    tempButton.superview.layer.shadowRadius = nil;
    tempButton.superview.layer.shadowOpacity = nil;

回答1:

I usually do the following to be safe.

  [[tempButton layer] setShadowOpacity:0.0];
  [[tempButton layer] setShadowRadius:0.0];
  [[tempButton layer] setShadowColor:nil];

Quartz is highly optimized and will not waste any time rendering if it doesn't have to.



回答2:

I would just remove the button, and replace it with an identical (but non-shadowed) button. Or keep both around and hide/unhide one of them. Sometimes it's easier to create a new UI object than munge around with an existing one.