rs / SDSegmentedControl

A drop-in remplacement for UISegmentedControl that mimic iOS 6 AppStore tab controls
MIT License
1.2k stars 180 forks source link

Problem under IOS8 for borderColor and borderWidth #69

Open nissaba opened 9 years ago

nissaba commented 9 years ago

This works fine under IOS7 and lower, under IOS8 the first time we push the view containing he SDSegmentControl all is ok. the next time around (Go back to previous view and back to this view) the segmentControl looses appearance setting we push it see below code for the border color and width.

SDSegmentedControl *segmentedControlAppearance = SDSegmentedControl.appearance; segmentedControlAppearance.backgroundColor = [UIColor colorWithHex:@"#453e34" alpha:alpha]; segmentedControlAppearance.borderColor = [UIColor whiteColor]; segmentedControlAppearance.arrowSize = 10; segmentedControlAppearance.arrowHeightFactor = 1; segmentedControlAppearance.arrowPosition = SDSegmentedArrowPositionTop; segmentedControlAppearance.borderWidth = 1;

we see the black defaults being drawn in black if we are on IOS8 which is inited under commonInits as

// Init border bottom layer [self.layer addSublayer:_borderBottomLayer = CAShapeLayer.layer]; if (!SD_IS_IOS7) { self.borderColor = UIColor.whiteColor; self.borderWidth = .5; } else { self.borderColor = UIColor.blackColor; self.borderWidth = .25; }

The fix I used was to directly set the color to withe and the width to 1 under this init bypassing the usage of the appearance setter.

This was the way I initially was setting in my viewDidLoad of the view being pushed as follows

- (void)segmentControlInit { // self.segmentControl.backgroundColor = [UIColor colorWithHex:@"#453e34" alpha:alpha];

SDSegmentedControl *segmentedControlAppearance = SDSegmentedControl.appearance; segmentedControlAppearance.backgroundColor = [UIColor colorWithHex:@"#453e34" alpha:alpha]; segmentedControlAppearance.borderColor = [UIColor whiteColor]; segmentedControlAppearance.arrowSize = 10; segmentedControlAppearance.arrowHeightFactor = 1; segmentedControlAppearance.arrowPosition = SDSegmentedArrowPositionTop; segmentedControlAppearance.borderWidth = 1;

SDSegmentView *segmenteViewAppearance = SDSegmentView.appearance;`

[segmenteViewAppearance setTitleColor:[UIColor colorWithRed:0.71 green:0.7 blue:0.7 alpha:1] forState:UIControlStateNormal]; [segmenteViewAppearance setTitleColor:[UIColor colorWithHex:@"#70ae47" alpha:1] forState:UIControlStateSelected]; segmenteViewAppearance.titleShadowOffset = CGSizeZero;

`SDStainView *stainViewAppearance = SDStainView.appearance;`

stainViewAppearance.backgroundColor = [UIColor clearColor]; stainViewAppearance.shadowColor = [UIColor colorWithHex:@"#453e34" alpha:1]; stainViewAppearance.shadowBlur = 0; stainViewAppearance.shadowOffset = CGSizeZero; }

satrun77 commented 9 years ago

I managed to set the border color and the width by setting the properties of SDSegmentedControl instance

self.segmentedControl.borderColor = [UIColor redColor];
self.segmentedControl.borderWidth = .4;
ragian commented 9 years ago

I have the same issue

 // SDSegmentedControl *segmentedControlAppearance = SDSegmentedControl.appearance;
   // segmentedControlAppearance.backgroundColor = [UIColor colorWithHexString:PRIMARY_COLOR];
   // segmentedControlAppearance.arrowSize = 7;
   // segmentedControlAppearance.arrowHeightFactor = 1.0;

    SDSegmentView *segmenteViewAppearance = SDSegmentView.appearance;

    //[segmenteViewAppearance setTitleFont:[UIFont fontWithName:FONT_LIGHT size:16.0]];
    [segmenteViewAppearance setTitleColor:[UIColor colorWithHexString:TEXT_COLOR_2] forState:UIControlStateNormal];
    [segmenteViewAppearance setTitleColor:[UIColor colorWithHexString:TEXT_COLOR_1] forState:UIControlStateSelected];
    //[segmenteViewAppearance setSelectedTitleFont:[UIFont fontWithName:FONT_LIGHT size:16.0]];

The commented lines are the lines "jump"