【发布时间】:2016-06-04 09:09:38
【问题描述】:
我正在尝试解决愚蠢的 Apple '没有带有自动布局的自定义字体' 的错误,但我遇到了以一种也适用于特征集合更新的方式实现它的问题。
我最初是在 viewDidLoad 上的延迟调用函数中以 0.5 的延迟运行代码,并且在那里它正在为设备正确更新字体大小和字体类型。但是,我了解到在那段时间也调用了 traitCollectionDidChange,所以我将代码移到了那里。现在字体类型没有更新,但字体大小正在更新。
这是我的代码,我可能忽略了一些愚蠢的东西:
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{
//[super traitCollectionDidChange: previousTraitCollection];
//Create horz/vert vars for easier iffing
UIUserInterfaceSizeClass viewHorizontal = self.view.traitCollection.horizontalSizeClass;
UIUserInterfaceSizeClass viewVertical = self.view.traitCollection.verticalSizeClass;
//Change font and font size depending on classes; really just the size but we need to set the font anyway
if (viewHorizontal == UIUserInterfaceSizeClassCompact && viewVertical == UIUserInterfaceSizeClassCompact){
agTtl_Text.font = [UIFont fontWithName:@"Hobo Std" size:36];
agSubttl_Text.font = [UIFont fontWithName:@"Hobo Std" size:20];
actBtn.titleLabel.font = [UIFont fontWithName:@"Hobo Std" size:20];
nAccBtn.titleLabel.font = [UIFont fontWithName:@"Hobo Std" size:20];
} else if (viewHorizontal == UIUserInterfaceSizeClassCompact && viewVertical == UIUserInterfaceSizeClassRegular){
agTtl_Text.editable = YES; //still need this iOS 6 hack?
agTtl_Text.font = [UIFont fontWithName:@"Hobo Std" size:35];
agSubttl_Text.font = [UIFont fontWithName:@"Hobo Std" size:20];
actBtn.titleLabel.font = [UIFont fontWithName:@"Hobo Std" size:30];
nAccBtn.titleLabel.font = [UIFont fontWithName:@"Hobo Std" size:30];
agTtl_Text.editable = NO; //still need this iOS 6 hack?
}
}
【问题讨论】:
标签: ios objective-c size-classes ios-autolayout