答案 0 :(得分:0)
要设置背景颜色,请使用此代码
protocol Presentable {
associatedtype View: ViewAble
weak var view: View? {get set}
init(with view: View)
func onAttach(view: View)
func onDetach()
var isAttached: Bool {get}
}
extension Presentable {
var isAttached: Bool {
return view != nil
}
}
class Presenter: Presentable {
weak var view: ViewAble? {
didSet {
if let view = view {
onAttach(view: view)
} else {
onDetach()
}
}
}
required init(with view: ViewAble) {
self.view = view
}
func onAttach(view: View) {
//pre set up on construction
}
func onDetach() {
//release some resource on destroying view
}
}
@objc protocol ViewAble: class {
@objc optional func showError(_ message: String, _ callBack: (() -> Void)?)
}
extension ViewAble where Self: UIViewController {
func showAlert(_ message: String?, _ callBack: (() -> Void)? = nil) {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default) { action in
callBack?()
})
self.present(alertController, animated: true, completion: callBack)
}
func showLoading() {
//show default Loading here and override if want custom
}
func stopLoading() {
//stop default Loading
}
}
class ViewController: ViewAble {
}
要更改文字和字体,请使用此代码
self.navigationController?.setBackgroundColor(UIColor.blue)
试试这个