Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did this by creating my own control, subclassing UIControl since Apple doesn't recommend screwing with the view hierarchy of UIButton. I add a background imageView representing the standard background image of the button, and a "glowing" imageView above the background to represent the lit-up state, and toggle its opacity to make it pulse.</p> <p>I additionally toggle the layer's shadow opacity to make it glow.</p> <p><strong>Initializing Code:</strong></p> <pre><code>- (void)TS_commonButtonInit { UIImage *shoutoutBackground = [UIImage imageNamed:@"root-navigation-bar-share-button"]; UIImage *shoutoutHighlightedBackground = [UIImage imageNamed:@"root-navigation-bar-share-button-highlighted"]; UIImage *shoutoutPulseImage = [UIImage imageNamed:@"root-navigation-bar-share-button-glowing"]; shoutoutBackground = [shoutoutBackground stretchableImageWithLeftCapWidth:7 topCapHeight:0]; shoutoutHighlightedBackground = [shoutoutHighlightedBackground stretchableImageWithLeftCapWidth:7 topCapHeight:0]; shoutoutPulseImage = [shoutoutPulseImage stretchableImageWithLeftCapWidth:7 topCapHeight:0]; [[self backgroundView] setImage:shoutoutBackground]; [[self backgroundView] setHighlightedImage:shoutoutHighlightedBackground]; [self setGlowingImage:shoutoutPulseImage]; [self setExclusiveTouch:YES]; [self addSubview:[self backgroundView]]; [self addSubview:[self glowingImageView]]; [[self layer] setShadowColor:[[UIColor colorWithHexString:@"ffc521" alpha:1] CGColor]]; [[self layer] setShadowOpacity:0]; [[self layer] setShadowRadius:5]; [[self layer] setShadowOffset:CGSizeMake(0, 0)]; [[self layer] setShadowPath:[[UIBezierPath bezierPathWithRoundedRect:[self bounds] cornerRadius:6] CGPath]]; } </code></pre> <p><strong>Pulsing Code:</strong></p> <pre><code>- (void)pulse:(NSInteger)numberOfTimes { CGFloat pulseLength = .8; [[self glowingImageView] setAlpha:0]; CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; [pulseAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [pulseAnimation setDuration:pulseLength]; [pulseAnimation setRepeatCount:numberOfTimes]; [pulseAnimation setAutoreverses:YES]; [pulseAnimation setFromValue:@(0)]; [pulseAnimation setToValue:@(1)]; [pulseAnimation setRemovedOnCompletion:YES]; [[self layer] setShadowOpacity:0]; CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; [shadowAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [shadowAnimation setDuration:pulseLength]; [shadowAnimation setRepeatCount:numberOfTimes]; [shadowAnimation setAutoreverses:YES]; [shadowAnimation setFromValue:@(0)]; [shadowAnimation setToValue:@(1)]; [shadowAnimation setRemovedOnCompletion:YES]; [[[self glowingImageView] layer] addAnimation:pulseAnimation forKey:@"opacity"]; [[self layer] addAnimation:shadowAnimation forKey:@"shadowOpacity"]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload