DZNSegmentedControl
DZNSegmentedControl copied to clipboard
when items is not in english, setSelectedSegmentIndex will has no effect
when i init control as follow
_timeControl = [[DZNSegmentedControl alloc] initWithItems:@[NSLocalizedString(@"日榜", @""),
NSLocalizedString(@"周榜", @""),
NSLocalizedString(@"总榜", @"")]];
_timeControl.tintColor=FZLightColor;
when calling
[self.timeControl setSelectedSegmentIndex:2 animated:YES];
segmentIndex's tintColor is not FZLightColor
when i init control as follow
_timeControl = [[DZNSegmentedControl alloc] initWithItems:@[NSLocalizedString(@"day", @""),
NSLocalizedString(@"week", @""),
NSLocalizedString(@"all", @"")]];
_timeControl.tintColor=FZLightColor;
that will effect when calling setSelectedSegmentIndex:animated
I fix this issue by this way, i don't know whether it is right
- (void)setSelectedSegmentIndex:(NSInteger)segment animated:(BOOL)animated
{
if (self.selectedSegmentIndex == segment || self.isTransitioning) {
return;
}
[self unselectAllButtons];
self.userInteractionEnabled = NO;
_selectedSegmentIndex = segment;
_transitioning = YES;
void (^animations)() = ^void(){
self.selectionIndicator.frame = [self selectionIndicatorRect];
};
void (^completion)(BOOL finished) = ^void(BOOL finished){
self.userInteractionEnabled = YES;
_transitioning = NO;
[self.buttons[segment] setSelected:YES];//I add this line to fix
};
if (animated) {
CGFloat duration = (self.selectedSegmentIndex < 0.0f) ? 0.0f : self.animationDuration;
CGFloat damping = !self.bouncySelectionIndicator ? : 0.65f;
CGFloat velocity = !self.bouncySelectionIndicator ? : 0.5f;
[UIView animateWithDuration:duration
delay:0.0f
usingSpringWithDamping:damping
initialSpringVelocity:velocity
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:animations
completion:completion];
}
else {
animations();
completion(NO);
}
}
the diff is in the completion block, i call ''' [self.buttons[segment] setSelected:YES];//I add this line to fix ''' to set the button selected
Could your please fork this repo and submit a PR with the fix? Thanks!
Is this related to https://github.com/dzenbot/DZNSegmentedControl/pull/56 ?
yes, it is related to #56