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

标签 ios objective-c uisegmentedcontrol flat

我有一个通过 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/

相关文章:

ios - 如何在单击只读文本字段 iOS 时移动到下一个屏幕

swift - 使用像 UISwitch 这样的 UISegmentedControl

ios - UISegmentedControl 在触摸后恢复到原始帧

ios - "Data is Nil"值来自删除 ios 中的 api 值

iphone - 如何判断当前设备是iPhone还是iPad?

ios - 如何在 UITableView 本身上设置 DropShadow

ios - 如何取消与外围设备的挂起本地连接

arrays - 索引超出范围将日期转换为字符串组件

ios - 如何检测之前是否显示过位置服务弹出窗口

ios - ASP.NET 检索 iOS 应用程序到期日期