gpt4 book ai didi

ios - 快速设置整个应用程序的导航栏后退按钮图像

转载 作者:行者123 更新时间:2023-11-28 12:14:26 25 4
gpt4 key购买 nike

我正在 AddDelegate 中设置导航栏后退按钮,但设置不正确。

我试过下面的代码:

let backButtonImage = backImage?.withRenderingMode(.alwaysOriginal).resizableImage(withCapInsets: UIEdgeInsetsMake((backImage?.size.height)!, (backImage?.size.width)!, 0, 0))
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backButtonImage, for: .normal, barMetrics: .default)
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-400, 0), for: .default)

来自 here .

但用户界面不正确:

enter image description here

我也试过下面的代码:

UINavigationBar.appearance().backIndicatorImage = backButtonImage
UINavigationBar.appearance().backIndicatorTransitionMaskImage = backButtonImage
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -80.0), for: .default)

看起来像这样:

enter image description here

但它在终端中给出了约束问题:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x600000098510 UILayoutGuide:0x6040007aca20'BackButtonGuide(0x7f8143611390)'.height == 44 (active)>",
"<NSLayoutConstraint:0x60000029e320 _UIButtonBarButton:0x7f814349d110.top == UILayoutGuide:0x6040007aca20'BackButtonGuide(0x7f8143611390)'.top (active)>",
"<NSLayoutConstraint:0x60000029de20 _UIButtonBarButton:0x7f814349d110.bottom == UILayoutGuide:0x6040007aca20'BackButtonGuide(0x7f8143611390)'.bottom (active)>",
"<NSLayoutConstraint:0x60400049d790 _UIModernBarButton:0x7f81434a4800'Back'.lastBaseline == UILayoutGuide:0x6000001b51c0'UIViewLayoutMarginsGuide'.bottom - 80 (active)>",
"<NSLayoutConstraint:0x60400049d1a0 _UIModernBarButton:0x7f81434a4800'Back'.top >= _UIButtonBarButton:0x7f814349d110.top (active)>",
"<NSLayoutConstraint:0x600000481040 UIButtonLabel:0x7f81434a30d0'Back'.centerY == _UIModernBarButton:0x7f81434a4800'Back'.centerY + 1.5 (active)>",
"<NSLayoutConstraint:0x60000029ea00 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x6000001b51c0'UIViewLayoutMarginsGuide']-(16)-| (active, names: '|':_UIButtonBarButton:0x7f814349d110 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000481040 UIButtonLabel:0x7f81434a30d0'Back'.centerY == _UIModernBarButton:0x7f81434a4800'Back'.centerY + 1.5 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.


[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;

(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60000029f1d0 _UIModernBarButton:0x7f814360f630.bottom == UILayoutGuide:0x6040007ac940'UIViewLayoutMarginsGuide'.bottom + 84.5 (active)>",
"<NSLayoutConstraint:0x600000287bc0 V:[_UIModernBarButton:0x7f814360f630]-(>=0)-| (active, names: '|':_UIButtonBarButton:0x7f814360d8a0 )>",
"<NSLayoutConstraint:0x604000488930 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x6040007ac940'UIViewLayoutMarginsGuide']-(16)-| (active, names: '|':_UIButtonBarButton:0x7f814360d8a0 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000029f1d0 _UIModernBarButton:0x7f814360f630.bottom == UILayoutGuide:0x6040007ac940'UIViewLayoutMarginsGuide'.bottom + 84.5 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

还有其他方法吗,还是我做错了什么?

最佳答案

引用@Rajamohan-s 的回答:

Change UINavigationBar back button text and font from AppDelegate using Swift

你可以用下面的代码来做;

 extension UINavigationItem{

override open func awakeFromNib() {
super.awakeFromNib()

let backItem = UIBarButtonItem()
backItem.title = "Hello"


if let font = UIFont(name: "Copperplate-Light", size: 32){
backItem.setTitleTextAttributes([NSFontAttributeName:font], for: .normal)
}else{

print("Font Not available")
}
/*Changing color*/
backItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.green], for: .normal)

self.backBarButtonItem = backItem
}

}

关于ios - 快速设置整个应用程序的导航栏后退按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47263258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com