UIBarButtonItem不会改变iOS 10上的颜色

问题描述 投票:0回答:1

所以关于我的另一个问题HERE,我现在有一个我发现的新问题。在iOS 11上我可以更改禁用按钮上的颜色,但在iOS 10.3.1模拟器上,它不会改变。

我正在尝试实现Safari的按钮格式,如果页面无法前进或后退,它会禁用按钮。以下代码适用于IOS 11,但不适用于IOS 11。

   //Toolbar actions
BOOL ableToGoBack = [self.webView canGoBack];
BOOL ableToGoForward = [self.webView canGoForward];

if (ableToGoBack == NO) {
    back.enabled = NO;
    back.tintColor = [[UIColor alloc] initWithWhite:0 alpha:0.5f];
    [self.view hideToastActivity];

}else {
    back.enabled = (self.webView.canGoBack);
}

if (ableToGoForward == NO) {
    forward.enabled = NO;
    forward.tintColor = [[UIColor alloc] initWithWhite:0 alpha:0.5f];
    [self.view hideToastActivity];

}else {
    forward.enabled = (self.webView.canGoForward);
}

我有一个自定义工具栏,但我已经尝试过禁用其他人建议的色调外观,但没有运气。以及在类似遭遇中发现的一些其他建议。

任何帮助将不胜感激,谢谢。

ios objective-c uibarbuttonitem wkwebview
1个回答
0
投票

所以我想我明白了。以下是对我有用的东西。我有一个控制工具栏色调的开关,所以你会注意到还有一些额外的代码。

    //Toolbar actions
BOOL ableToGoBack = [self.webView canGoBack];
BOOL ableToGoForward = [self.webView canGoForward];

if (ableToGoBack == NO) {
    back.enabled = NO;
    [self.view hideToastActivity];

    BOOL isblack = [[NSUserDefaults standardUserDefaults] boolForKey:@"darkKeyboard"];
    if (isblack) {
        back.tintColor = [[UIColor alloc] initWithWhite:0.0f alpha:0.1f];
        [back setTitleTextAttributes:@{NSFontAttributeName:
                                           [UIFont fontWithName:@"fontello"
                                                           size:23],
                                       NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:1.0f alpha:0.1f]}
                            forState:UIControlStateNormal];
    }else{
        back.tintColor = [[UIColor alloc] initWithWhite:0.0f alpha:0.1f];
        [back setTitleTextAttributes:@{NSFontAttributeName:
                                           [UIFont fontWithName:@"fontello"
                                                           size:23],
                                       NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:0.0f alpha:0.1f]}
                            forState:UIControlStateNormal];
    }


}else {
    back.enabled = (self.webView.canGoBack);
}

if (ableToGoForward == NO) {
    forward.enabled = NO;
    [self.view hideToastActivity];

    BOOL isblack = [[NSUserDefaults standardUserDefaults] boolForKey:@"darkKeyboard"];
    if (isblack) {
        forward.tintColor = [[UIColor alloc] initWithWhite:1.0f alpha:0.1f];
        [forward setTitleTextAttributes:@{NSFontAttributeName:
                                              [UIFont fontWithName:@"fontello"
                                                              size:23],
                                          NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:1.0f alpha:0.1f]}
                               forState:UIControlStateNormal];
    }else{
        forward.tintColor = [[UIColor alloc] initWithWhite:0.0f alpha:0.1f];
        [forward setTitleTextAttributes:@{NSFontAttributeName:
                                              [UIFont fontWithName:@"fontello"
                                                              size:23],
                                          NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:0.0f alpha:0.1f]}
                               forState:UIControlStateNormal];
    }

}else {
    forward.enabled = (self.webView.canGoForward);
}
© www.soinside.com 2019 - 2024. All rights reserved.