session-ios/SignalMessaging/Views/OWSButton.swift

65 lines
1.4 KiB
Swift
Raw Normal View History

2018-11-15 03:01:21 +01:00
//
2019-02-26 19:18:52 +01:00
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
2018-11-15 03:01:21 +01:00
//
import UIKit
@objc
public class OWSButton: UIButton {
@objc
var block: () -> Void = { }
// MARK: -
@objc
2019-03-08 06:05:58 +01:00
public init(block: @escaping () -> Void = { }) {
2018-11-15 03:01:21 +01:00
super.init(frame: .zero)
2019-02-26 19:18:52 +01:00
self.block = block
addTarget(self, action: #selector(didTap), for: .touchUpInside)
}
@objc
2019-03-08 06:05:58 +01:00
public init(title: String, block: @escaping () -> Void = { }) {
2019-02-26 19:18:52 +01:00
super.init(frame: .zero)
2018-11-15 03:01:21 +01:00
self.block = block
2019-02-26 19:18:52 +01:00
addTarget(self, action: #selector(didTap), for: .touchUpInside)
setTitle(title, for: .normal)
2018-11-15 03:01:21 +01:00
}
2019-02-27 20:14:33 +01:00
@objc
2019-03-08 06:05:58 +01:00
public init(imageName: String,
tintColor: UIColor?,
2019-02-27 20:14:33 +01:00
block: @escaping () -> Void = { }) {
super.init(frame: .zero)
self.block = block
addTarget(self, action: #selector(didTap), for: .touchUpInside)
2019-02-27 20:40:12 +01:00
setImage(imageName: imageName)
self.tintColor = tintColor
}
@objc
public func setImage(imageName: String) {
2019-02-27 20:14:33 +01:00
if let image = UIImage(named: imageName) {
setImage(image.withRenderingMode(.alwaysTemplate), for: .normal)
} else {
owsFailDebug("Missing asset: \(imageName)")
}
}
public required init?(coder aDecoder: NSCoder) {
2018-11-15 03:01:21 +01:00
fatalError("init(coder:) has not been implemented")
}
// MARK: -
@objc
func didTap() {
block()
}
}