12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // KMBaseXibView.swift
- // PDF Master
- //
- // Created by lizhe on 2023/2/15.
- // xib初始化
- import Cocoa
- class KMBaseXibView: NSView {
- @IBOutlet var contentView: NSView!
- // MARK: 初始化
- public required init?(coder decoder: NSCoder) {
- super.init(coder: decoder)
- self.initContentView()
- self.setup()
- self.updateUI()
- self.updateLanguage()
- self.reloadData()
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
- self.initContentView()
- self.setup()
- self.updateUI()
- self.updateLanguage()
- self.reloadData()
- self.addNotification()
- }
-
- private func initContentView() {
- let isExist = Bundle.main.path(forResource: String(describing:self.classForCoder.self), ofType: "nib")
- if isExist != nil {
- var topLevelArray: NSArray? = nil
- //绑定xib
- let resource = NSNib(nibNamed: String(describing: self.classForCoder.self),
- bundle: nil)
- if resource != nil {
- if (resource!.instantiate(withOwner: self, topLevelObjects: &topLevelArray)) {
- for view in topLevelArray! {
- if view is NSView {
- contentView = view as? NSView
- break
- }
- }
- }
-
- if contentView == nil {
- contentView = NSView()
- }
- addSubview(contentView)
- contentView.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint.activate([
- contentView.topAnchor.constraint(equalTo: topAnchor),
- contentView.leftAnchor.constraint(equalTo: leftAnchor),
- contentView.rightAnchor.constraint(equalTo: rightAnchor),
- contentView.bottomAnchor.constraint(equalTo: bottomAnchor)])
- contentView.updateConstraintsForSubtreeIfNeeded()
- }
- }
- }
-
- func setup() {
-
- }
-
- //刷新界面UI 和 数据
- func reloadData() {
- }
-
- func updateLanguage() {
-
- }
-
- func updateUI() {
-
- }
-
- func resetData() {
-
- }
-
- func addNotification() {
-
- }
-
- func removeNotification() {
-
- }
- }
|