在运行时切换到FlatUIKit分段控件

时间:2013-11-22 09:53:52

标签: ios objective-c uisegmentedcontrol flat

我通过故事板设置了UISegmentedControl,我有一个插座。在运行时,我有一个方法来检查操作系统是否小于iOS7,如果是,我需要将UISegmentedControl替换为FlatUIKit的分段控件。该类名为FUISegmentedControl,它继承自UISegmentedControl。这是初始化方法:

+ (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]];
    }
}

我不知道如何在运行时用UISegmentedControl替换FUISegmentedControl

以下是FlatUIKit的GitHub链接: FlatUIKit

1 个答案:

答案 0 :(得分:1)

我用代码而不是故事板对此问题进行了排序。

我检查IOS是否<7;

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

我以编程方式而不是故事板添加了我的控件。

if (IS_IOS7)
{
    self.segmCntr = [[UISegmentedControl alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
}
else
{
    self.segmCntr = [[FUISegmentedControl alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
}