12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // KMToolbarPageInputItemView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/10/12.
- //
- import Cocoa
- class KMToolbarPageInputItemView: NSView {
- private lazy var contentView_: NSView = {
- let view = NSView()
- return view
- }()
-
- private lazy var inputBox_: NSBox = {
- let box = NSBox()
- box.boxType = .custom
- return box
- }()
-
- private lazy var inputTF_: NSTextField = {
- let view = NSTextField()
- view.formatter = NumberFormatter()
- view.drawsBackground = false
- view.isBordered = false
- view.focusRingType = .none
- return view
- }()
-
- private lazy var numberLabel_: NSTextField = {
- let view = NSTextField(labelWithString: "")
- view.font = KMToolbarMainItemView.textFont
- view.textColor = KMAppearance.subtitleColor()
- return view
- }()
-
- private lazy var titleLabel_: NSTextField = {
- let view = NSTextField(labelWithString: NSLocalizedString("Page", comment: ""))
- view.font = KMToolbarMainItemView.textFont
- view.textColor = KMAppearance.subtitleColor()
- return view
- }()
-
- var totalNumber: Int = 0 {
- didSet {
- self.numberLabel_.stringValue = "/" + "\(self.totalNumber)"
- }
- }
-
- convenience init() {
- self.init(frame: NSMakeRect(0, 0, 80, 40))
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- self.initSubviews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- self.initSubviews()
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- func initSubviews() {
- self.addSubview(self.contentView_)
-
- self.contentView_.addSubview(self.inputBox_)
- self.contentView_.addSubview(self.numberLabel_)
- self.contentView_.addSubview(self.titleLabel_)
-
- self.inputBox_.contentView?.addSubview(self.inputTF_)
-
- self.contentView_.km_add_inset_constraint()
- self.inputBox_.km_add_leading_constraint(constant: 2)
- self.inputBox_.km_add_top_constraint(constant: 2)
- self.inputBox_.km_add_width_constraint(constant: 45)
- self.inputBox_.km_add_height_constraint(constant: 22)
- self.numberLabel_.km_add_leading_constraint(equalTo: self.inputBox_, attribute: .trailing, constant: 2)
- self.numberLabel_.km_add_centerY_constraint(equalTo: self.inputBox_)
- self.titleLabel_.km_add_top_constraint(equalTo: self.inputBox_, attribute: .bottom, constant: 2)
- self.titleLabel_.km_add_centerX_constraint()
-
- self.inputTF_.km_add_leading_constraint()
- self.inputTF_.km_add_centerX_constraint()
- self.inputTF_.km_add_centerY_constraint()
- }
-
- }
|