dzenbot / DZNSegmentedControl

A drop-in replacement for UISegmentedControl for showing counts, to be used typically on a user profile

Home Page:https://www.cocoacontrols.com/controls/dznsegmentedcontrol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tall selection indicator covers segment title

ndmeiri opened this issue · comments

I'm trying to use a tall selection indicator as shown in the graphic below. However, when a segment is selected, the indicator stays behind the titles but then covers them after the animation completes. I tried commenting out the line [self bringSubviewToFront:_selectionIndicator]; in -layoutSubviews but this did not fix the problem.

covering selection indicator

Looks nice! Did you figured it out?

Not yet, unfortunately.

I tried this out and it didn't need much fix.

Instead of [self bringSubviewToFront:_selectionIndicator] in -layoutSubviews, we must call [self sendSubviewToBack:_selectionIndicator];.

The rest, is just config stuff. The reason why the title wasn't showing it's because the button's selected state color was the same than the background color of the selection indicator.
So it's as easy as setting [self.control setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];

While calling self.control.selectionIndicatorHeight = self.control.height; to adjust the selection indicator's height to match the control's.

image

Ah, I can't believe I overlooked the fact the colors could've been the problem. Thank you!

I checked my code and it turns out I was actually setting the colors correctly. However, I examined a few lines where I configure the control and I noticed a potential issue:
If this line

[self.control setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; 

is executed before this line

self.control.tintColor = [UIColor redColor];

then the selection indicator and the selected title color both become red which causes it to look like the indicator is covering the selected segment.