【问题标题】:Tab bar text is too big after dismissing a modal view关闭模式视图后标签栏文本太大
【发布时间】:2015-10-16 15:35:57
【问题描述】:

在我的应用程序中,我有一个 TabBar 和一个 ViewController,它们通过使用 DelegateProtocol 以模态方式呈现。虽然一切都按预期工作,但我收到了一个奇怪的错误。当我关闭我的模态 ViewController 时,TabBarItems 的标签比以前大。之后即使调整大小也不起作用。

我正在像这样解雇我的模态 ViewController:

-(void)universalLoginFinished:(UniversalLoginModalViewController *)viewController {
    NSLog(@"Login successful");
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.isLoggedIn = YES;
    [self dismissViewControllerAnimated:YES completion:^{
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"MerriweatherSans-Regular" size:18.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];
        self.tabBarController.tabBar.translucent = NO;
        [self.tabBarController.tabBar setTintColor:UIColorFromRGB(0x0077B3)];
        [self viewDidLoad];
    }];
}

编辑

调用和关闭模态视图之前的我的 TabBar

调用和关闭模态视图后的我的 TabBar

我是否忘记了导致我的 TabBarItems 的标签变大的东西,还是我做错了什么?

【问题讨论】:

  • 可以添加截图吗?还请解释你为什么从一个方法调用 viewdidload ?
  • 我马上添加截图。在关闭模态视图后,我调用它来重新加载我的视图。 [self.view setNeedsDisplay] 不适合我。
  • 18号字体?也是以前的字体吗?
  • 是的,我只使用 18.0f 作为商品标签的尺寸。
  • 试着把它变成 9 看看,它的标签仍然扩大。我确定,这和大小有关!!!

标签: ios objective-c


【解决方案1】:

您已将字体大小设置为 18.0,这应该是它的样子。并且不清楚为什么在关闭模态视图控制器并调用ViewDidLoad 后需要更新标签栏外观。我想如果你设置completion:nil,你的问题就会消失。

您可能会采用一些更好的方法。就像您可以在 AppDelegate 中编写一个加载 TabBarController 及其 viewControllers 的方法。因此,首先您将登录屏幕显示为窗口的 RootViewController,然后登录完成后,您可以调用该方法从 AppDelegate 加载TabBarController。

【讨论】:

  • 感谢您的意见。我已根据您答案的第一部分更改了我的代码,但它并没有改变行为。我的标签还是太大了。
【解决方案2】:

在应用进一步测试后,我注意到字体负责更大的标签。我使用自定义字体“MerriWeatherSans-Regular”,它似乎与[UIFont fontWithName:fontName] 方法不兼容。使用“MerriWeatherSans”后,一切都按预期工作。

虽然它现在可以工作,但我感到很困惑,因为“MerriWeatherSans-Regular”在我的应用程序中的其他 ViewControllers 中工作。

为了完整起见,这里是我的最终代码:

-(void)universalLoginFinished:(UniversalLoginModalViewController *)viewController {
    NSLog(@"Login successful");
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.isLoggedIn = YES;

    [self dismissViewControllerAnimated:YES completion:nil];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"MerriweatherSans" size:18.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];
    self.tabBarController.tabBar.translucent = NO;
    [self.tabBarController.tabBar setTintColor:UIColorFromRGB(0x0077B3)];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多