В настоящее время я реализую несколько пользовательских UIBarButtonItem, когда я использую несколько пользовательских методов, чтобы изменить положение изображения кнопки, чтобы переместить его вправо от текста и добавить некоторые отступы.Однако, когда я покидаю экран и возвращаюсь, текст и изображения кнопок переключаются и искажаются, как это видно на прилагаемых изображениях.
![enter image description here](https://i.stack.imgur.com/Qh3dX.png)
![enter image description here](https://i.stack.imgur.com/TNOED.png)
Первое изображение - это то, как выглядит кнопка, когда я выхожу из экрана и возвращаюсь. Второе изображение - это то, как оно изначально выглядит.я включил код для uibarbuttonitem, если кто-то увидит что-то, что я не вижу, это вызывает проблему рендеринга, я был бы очень признателен.
import Foundation
import UIKit
class LocationManager: UIBarButtonItem {
var viewController: MainViewController?
lazy var customButton : UIButton = {
let customButton = UIButton(type: .system)
customButton.setImage(UIImage(named: "downArrow"), for: .normal)
customButton.imageEdgeInsets = UIEdgeInsetsMake(0, 20, 0, -10)
guard let customFont = UIFont(name: "NoirPro-SemiBold", size: 20) else {
fatalError("""
Failed to load the "CustomFont-Light" font.
Make sure the font file is included in the project and the font name is spelled correctly.
"""
)
}
customButton.semanticContentAttribute = UIApplication.shared
.userInterfaceLayoutDirection == .rightToLeft ? .forceLeftToRight : .forceRightToLeft
customButton.titleLabel?.font = customFont
customButton.setTitleColor(UIColor.black, for: .normal)
return customButton
}()
override init() {
super.init()
setupViews()
}
@objc func setupViews(){
customView = customButton
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}