HeshamMegid / HMSegmentedControl

A highly customizable drop-in replacement for UISegmentedControl.
Other
4.02k stars 835 forks source link

There is an issue in iOS7.1 #95

Closed xieweizhi closed 9 years ago

xieweizhi commented 9 years ago

Thanks @HeshamMegid , this is an awesome open source. But I encountered a problem using this. Here is how I setup the HMSegmentedControl in viewDidLoad

 _segmentControl = [[HMSegmentedControl alloc] initWithSectionTitles:titles];
    _segmentControl.frame = CGRectMake(0, 0, ScreenWidth, kTopViewHeight);
    _segmentControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
    _segmentControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
    _segmentControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    _segmentControl.verticalDividerEnabled = NO;
    _segmentControl.selectionIndicatorColor = [UIColor blackColor];
    _segmentControl.selectionIndicatorHeight = 2;

    [_segmentControl setTitleFormatter:^NSAttributedString *(HMSegmentedControl *segmentedControl, NSString *title, NSUInteger index, BOOL selected) {
        NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName : RGBAColor(190.0, 190.0, 190.0, 1.0),
              NSFontAttributeName : [UIFont systemFontOfSize:15.0]}];
        if (selected) {
            attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName : [UIColor blackColor],
                                                                                                          NSFontAttributeName : [UIFont systemFontOfSize:15.0]}];
        }
        return attString;
    }];

    __weak typeof(_swipeView) weakSwipeView = _swipeView;
    [_segmentControl setIndexChangeBlock:^(NSInteger index) {
        [weakSwipeView scrollToItemAtIndex:index duration:0.3];
    }];

    [self.view addSubview:_segmentControl];

and I got this error message:

 <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Why this happens? This is annoying , but nothing harmful right now .

HeshamMegid commented 9 years ago

This has been fixed in the latest commit on master which hasn't been released as a pod yet. If you point your pod installation to use the latest commit from the master branch, you should no longer see this.

xieweizhi commented 9 years ago

@HeshamMegid thanks for pointing out ^ ^