Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

when items is not in english, setSelectedSegmentIndex will has no effect #58

Open
bellchen opened this issue Sep 11, 2015 · 4 comments
Open

Comments

@bellchen
Copy link

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

@bellchen
Copy link
Author

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

@dzenbot
Copy link
Owner

dzenbot commented Sep 15, 2015

Could your please fork this repo and submit a PR with the fix? Thanks!

@dzenbot
Copy link
Owner

dzenbot commented Sep 21, 2015

Is this related to #56 ?

@bellchen
Copy link
Author

yes, it is related to #56

bellchen added a commit to bellchen/DZNSegmentedControl that referenced this issue Sep 30, 2015
bellchen added a commit to bellchen/DZNSegmentedControl that referenced this issue Sep 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants