mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-20 15:27:32 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
93
mobile/ios/Client/Frontend/Widgets/Toolbar.swift
Normal file
93
mobile/ios/Client/Frontend/Widgets/Toolbar.swift
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
import SnapKit
|
||||
|
||||
class Toolbar: UIView {
|
||||
var drawTopBorder = false
|
||||
var drawBottomBorder = false
|
||||
var drawSeperators = false
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
self.backgroundColor = UIColor.clear
|
||||
|
||||
// Allow the view to redraw itself on rotation changes
|
||||
contentMode = UIViewContentMode.redraw
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
fileprivate func drawLine(_ context: CGContext, width: CGFloat, start: CGPoint, end: CGPoint) {
|
||||
context.setStrokeColor(UIConstants.BorderColor.cgColor)
|
||||
context.setLineWidth(width * (1 / UIScreen.main.scale) )
|
||||
context.move(to: CGPoint(x: start.x, y: start.y))
|
||||
context.addLine(to: CGPoint(x: end.x, y: end.y))
|
||||
context.strokePath()
|
||||
}
|
||||
|
||||
override func draw(_ rect: CGRect) {
|
||||
if let context = UIGraphicsGetCurrentContext() {
|
||||
if drawTopBorder {
|
||||
drawLine(context, width: 1, start: CGPoint(x: 0, y: 0), end: CGPoint(x: frame.width, y: 0))
|
||||
}
|
||||
|
||||
if drawBottomBorder {
|
||||
drawLine(context, width: 1, start: CGPoint(x: 0, y: frame.height), end: CGPoint(x: frame.width, y: frame.height))
|
||||
}
|
||||
|
||||
if drawSeperators {
|
||||
var skippedFirst = false
|
||||
for view in subviews {
|
||||
if skippedFirst {
|
||||
let frame = view.frame
|
||||
drawLine(context,
|
||||
width: 0.5,
|
||||
start: CGPoint(x: floor(frame.origin.x), y: 0),
|
||||
end: CGPoint(x: floor(frame.origin.x), y: self.frame.height))
|
||||
} else {
|
||||
skippedFirst = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addButtons(_ buttons: [UIButton]) {
|
||||
for button in buttons {
|
||||
button.setTitleColor(UIColor.black, for: UIControlState())
|
||||
button.setTitleColor(UIColor.gray, for: UIControlState.disabled)
|
||||
button.imageView?.contentMode = UIViewContentMode.scaleAspectFit
|
||||
addSubview(button)
|
||||
}
|
||||
}
|
||||
|
||||
override func updateConstraints() {
|
||||
var prev: UIView? = nil
|
||||
for view in self.subviews {
|
||||
view.snp.remakeConstraints { make in
|
||||
if let prev = prev {
|
||||
make.left.equalTo(prev.snp.right)
|
||||
} else {
|
||||
make.left.equalTo(self)
|
||||
}
|
||||
prev = view
|
||||
|
||||
var bottomInset: CGFloat = 0.0
|
||||
if #available(iOS 11, *) {
|
||||
if let window = UIApplication.shared.keyWindow {
|
||||
bottomInset = window.safeAreaInsets.bottom
|
||||
}
|
||||
}
|
||||
make.top.equalTo(self)
|
||||
make.height.equalTo(UIConstants.BottomToolbarHeight - bottomInset)
|
||||
make.width.equalTo(self).dividedBy(self.subviews.count)
|
||||
}
|
||||
}
|
||||
super.updateConstraints()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue