2019-12-19 17:32:49 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-09-07 22:37:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
|
|
protocol RemoveCellDelegate: class {
|
|
|
|
|
func removeCellDidTapButton(_ cell: RemoveCell)
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-12 20:12:23 +00:00
|
|
|
final class RemoveCell: UICollectionViewCell {
|
2016-09-07 22:37:59 +00:00
|
|
|
|
|
|
|
|
weak var delegate: RemoveCellDelegate?
|
|
|
|
|
|
2017-04-11 20:20:56 +00:00
|
|
|
private lazy var label: UILabel = {
|
2016-09-07 22:37:59 +00:00
|
|
|
let label = UILabel()
|
2016-10-24 18:06:17 +00:00
|
|
|
label.backgroundColor = .clear
|
2016-09-07 22:37:59 +00:00
|
|
|
self.contentView.addSubview(label)
|
|
|
|
|
return label
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
fileprivate lazy var button: UIButton = {
|
|
|
|
|
let button = UIButton(type: .custom)
|
2019-12-19 05:50:02 +00:00
|
|
|
button.setTitle("Remove", for: UIControl.State())
|
|
|
|
|
button.setTitleColor(.blue, for: UIControl.State())
|
2016-10-24 18:06:17 +00:00
|
|
|
button.backgroundColor = .clear
|
2016-09-07 22:37:59 +00:00
|
|
|
button.addTarget(self, action: #selector(RemoveCell.onButton(_:)), for: .touchUpInside)
|
|
|
|
|
self.contentView.addSubview(button)
|
|
|
|
|
return button
|
|
|
|
|
}()
|
|
|
|
|
|
2017-04-11 20:20:56 +00:00
|
|
|
var text: String? {
|
|
|
|
|
get {
|
|
|
|
|
return label.text
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
label.text = newValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 22:37:59 +00:00
|
|
|
override func layoutSubviews() {
|
|
|
|
|
super.layoutSubviews()
|
2020-10-03 08:37:52 +00:00
|
|
|
contentView.backgroundColor = UIColor.background
|
2016-09-07 22:37:59 +00:00
|
|
|
let bounds = contentView.bounds
|
|
|
|
|
let divide = bounds.divided(atDistance: 100, from: .maxXEdge)
|
|
|
|
|
label.frame = divide.slice.insetBy(dx: 15, dy: 0)
|
|
|
|
|
button.frame = divide.remainder
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-22 13:34:52 +00:00
|
|
|
@objc func onButton(_ button: UIButton) {
|
2016-09-07 22:37:59 +00:00
|
|
|
delegate?.removeCellDidTapButton(self)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|