Oliver
Oliver

Reputation: 619

Particular View or Label of Segmented Control for Index

I want to reach particular view or label of segmented control. In my case, when user press the button, second part of segmented control should be blinked, not all of segmented control.

Also my blink func is here:

extension UIView{
func blink() {
    self.alpha = 0.2
    UIView.animate(withDuration: 1, delay: 0.0, options: [.curveLinear, .autoreverse], animations: {self.alpha = 1.0}, completion: nil)

}

}

Upvotes: 2

Views: 234

Answers (1)

Sweeper
Sweeper

Reputation: 274320

I don't think you can get the different segments of a segmented control as UIViews. I suspect that might involve using some private APIs.

Workarounds:

assuming your background color is white, you can add a white rectangular UIView on top of the segment that you want to flash. Adjust its size so that it covers second segment fully and animate that view's alpha: from 0 to 0.8, then to 0 again.

Alternatively, you can find a library that allows you to get the separate segments yourself. Or write your own UIControl subclass that exposes the segments.

Upvotes: 1

Related Questions