diff options
author | Eric Kuck <eric@bluelinelabs.com> | 2018-12-13 12:58:50 -0600 |
---|---|---|
committer | Eric Kuck <eric@bluelinelabs.com> | 2018-12-13 12:58:50 -0600 |
commit | 05d750539b91eff582ff6a789fcdcab73bb5f7bb (patch) | |
tree | 0a59939a0805567ea1c4b310d78e4d4c9394cb96 /WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift | |
parent | Avoid escaping heap allocation (diff) | |
download | wireguard-apple-05d750539b91eff582ff6a789fcdcab73bb5f7bb.tar.xz wireguard-apple-05d750539b91eff582ff6a789fcdcab73bb5f7bb.zip |
Reorganized ViewControllers (split out UIViews and UITableViewCells into their own classes)
All swiftlint warnings except one fixed up
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift b/WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift new file mode 100644 index 0000000..5114c09 --- /dev/null +++ b/WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018 WireGuard LLC. All Rights Reserved. + +import UIKit + +class BorderedTextButton: UIView { + let button: UIButton = { + let button = UIButton(type: .system) + button.titleLabel?.font = UIFont.preferredFont(forTextStyle: .body) + button.titleLabel?.adjustsFontForContentSizeCategory = true + return button + }() + + override var intrinsicContentSize: CGSize { + let buttonSize = button.intrinsicContentSize + return CGSize(width: buttonSize.width + 32, height: buttonSize.height + 16) + } + + var title: String { + get { return button.title(for: .normal) ?? "" } + set(value) { button.setTitle(value, for: .normal) } + } + + var onTapped: (() -> Void)? + + init() { + super.init(frame: CGRect.zero) + + layer.borderWidth = 1 + layer.cornerRadius = 5 + layer.borderColor = button.tintColor.cgColor + + addSubview(button) + button.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + button.centerXAnchor.constraint(equalTo: self.centerXAnchor), + button.centerYAnchor.constraint(equalTo: self.centerYAnchor) + ]) + + button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) + } + + @objc func buttonTapped() { + onTapped?() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} |