Question

I have a UISegmentedControl set through a storyboard and I have an outlet for it. In runtime, I have a method which checks if the operating system is less than iOS7 and if it is I need to replace the UISegmentedControl to a segmented control from the FlatUIKit. The class is called FUISegmentedControl and it inherits from UISegmentedControl. Here is it's initialize method:

+ (void)initialize {
    if (self == [FUISegmentedControl class]) {
        FUISegmentedControl *appearance = [self appearance];
        [appearance setCornerRadius:5.0f];
        [appearance setSelectedColor:[AppereanceConfiguration defaultTintColor]];
        [appearance setDeselectedColor:[UIColor whiteColor]];
        [appearance setDividerColor:[AppereanceConfiguration defaultTintColor]];
        [appearance setSelectedFont:[AppereanceConfiguration fontLightWithSize:16]];
        [appearance setDeselectedFont:[AppereanceConfiguration fontLightWithSize:16]];
        [appearance setSelectedFontColor:[UIColor whiteColor]];
        [appearance setDeselectedFontColor:[AppereanceConfiguration defaultTintColor]];
    }
}

I don't know how to replace the UISegmentedControl with this FUISegmentedControl at runtime.

Here is a GitHub link to the FlatUIKit: FlatUIKit

Was it helpful?

Solution

I sorted this issue with code instead of storyboard.

I check if IOS <7 with this:

#define IS_IOS7 ([[UIDevice currentDevice].systemVersion floatValue] >=7)

And I added my controls programatically rather than with storyboard.

if (IS_IOS7)
{
    self.segmCntr = [[UISegmentedControl alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
}
else
{
    self.segmCntr = [[FUISegmentedControl alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top