默认情况下,在我们的应用程序中,UINavigationBarItems的外观如下
NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor clearColor], NSForegroundColorAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];
基本上,我们将标题设置为透明。
这会影响与其他组件(如UIImagePicker)的潜在集成,但基本上我们在显示图像选择器时会回滚这种外观。
NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkGrayColor], NSForegroundColorAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];
但是,如果在UITextView中,我们有一个链接或一封电子邮件,并且通过3D触摸,系统会显示一个用于发送消息或添加联系人的菜单,那么该应用程序会显示透明按钮,从而导致可用性差。
解决方法1
如果视图已经弹出,或者只是因为另一个组件(图像选择器、添加联系人、短信等)而隐藏,我们会在视图中检测到视图将消失
- (void) viewWillDisappear:(BOOL)animated {
BOOL isBeingRemoved = [self isMovingFromParentViewController] || self.isBeingDismissed;
if (isBeingRemoved) {
// Hidding the UINavigationBarItem title
NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor clearColor], NSForegroundColorAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];
} else {
// Make visible the UINavigationBarItem title
NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkGrayColor], NSForegroundColorAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];
}
[super viewWillDisappear:animated];
}
但通过这样做,应用程序外观会更新,应用程序标题不再透明。
解决方案2
我们尝试在ViewWillBeen中应用透明,在ViewWillBeside中应用暗光线,它适用于图像选择器,但不适用于其他应用程序。
解决方案3
我们还尝试设置darkGrayColor,但没有使用ViewWillEnglishe中的外观,但没有成功。
self.navigationcontroller.navigationbar.titletextattributes
有什么建议吗?