我希望在viewDidLoad
扩展名中调整UIViewController
但在initialize()
中覆盖的swift3
方法已被swift4
支持并且swift3
不支持。任何人都可以给我任何解决方案吗?我在 extension UIViewController {
open override class func initialize() {
guard self === UIViewController.self else { return }
swizzling(self)
}
// MARK: - Method Swizzling
func nsh_viewDidLoad() {
self.nsh_viewDidLoad()
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}
}
中的代码如下所示。
private let swizzling: (UIViewController.Type) -> () = { viewController in
let originalSelector = #selector(viewController.viewDidLoad)
let swizzledSelector = #selector(viewController.nsh_viewDidLoad)
let originalMethod = class_getInstanceMethod(viewController, originalSelector)
let swizzledMethod = class_getInstanceMethod(viewController, swizzledSelector)
let didAddMethod = class_addMethod(viewController, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
if didAddMethod {
class_replaceMethod(viewController, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
} else {
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
并有一个全局方法
{% assign min = 65 %}
{% assign max = 80 %}
{% assign diff = max | minus: min %}
{% assign randomNumber = "now" | date: "%N" | modulo: diff | plus: min %}
答案 0 :(得分:0)
我在AppDelegate
中添加了以下代码,如果是混合
let barButtonItemAppearance = UIBarButtonItem.appearance()
barButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)
barButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .highlighted)