我有一个通过 Storyboard设置的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]];
}
}
我不知道如何在运行时用此 FUISegmentedControl
替换 UISegmentedControl
。
以下是 FlatUIKit 的 GitHub 链接: FlatUIKit
最佳答案
我用代码而不是 Storyboard解决了这个问题。
我检查 IOS <7 是否使用以下命令:
#define IS_IOS7 ([[UIDevice currentDevice].systemVersion floatValue] >=7)
我以编程方式添加了控件,而不是使用 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)];
}
关于ios - 在运行时切换到FlatUIKit分段控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20141822/