| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //
- // JCDoubleButtonCell.swift
- // JChat
- //
- // Created by deng on 2017/5/16.
- // Copyright © 2017年 HXHG. All rights reserved.
- //
- import UIKit
- @objc public protocol JCDoubleButtonCellDelegate: NSObjectProtocol {
- @objc optional func doubleButtonCell(clickLeftButton button: UIButton)
- @objc optional func doubleButtonCell(clickRightButton button: UIButton)
- }
- class JCDoubleButtonCell: UITableViewCell {
- open weak var delegate: JCDoubleButtonCellDelegate?
-
- var leftButtonTitle: String {
- get {
- return leftButton.titleLabel?.text ?? ""
- }
- set {
- leftButton.setTitle(newValue, for: .normal)
- }
- }
-
- var leftButtonColor: UIColor {
- get {
- return color
- }
- set {
- color = newValue
- leftButton.backgroundColor = newValue
- }
- }
-
- var rightButtonTitle: String {
- get {
- return rightButton.titleLabel?.text ?? ""
- }
- set {
- rightButton.setTitle(newValue, for: .normal)
- }
- }
-
- var rightButtonColor: UIColor {
- get {
- return color
- }
- set {
- color = newValue
- rightButton.backgroundColor = newValue
- }
- }
-
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- _init()
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
- _init()
- }
-
- private var color = UIColor(netHex: 0xfb4747)
- private lazy var leftButton: UIButton = UIButton()
- private lazy var rightButton: UIButton = UIButton()
-
- //MARK: - private func
- private func _init() {
- backgroundColor = .clear
- leftButton.addTarget(self, action: #selector(_clickLeftButton(_:)), for: .touchUpInside)
- leftButton.setTitle("加好友", for: .normal)
- leftButton.setTitleColor(.black, for: .normal)
- leftButton.backgroundColor = .white
- leftButton.layer.cornerRadius = 3.0
- leftButton.layer.masksToBounds = true
- contentView.addSubview(leftButton)
-
- rightButton.addTarget(self, action: #selector(_clickRightButton(_:)), for: .touchUpInside)
- rightButton.setTitle("发送消息", for: .normal)
- rightButton.layer.cornerRadius = 3.0
- rightButton.layer.masksToBounds = true
- rightButton.backgroundColor = color
- contentView.addSubview(rightButton)
-
- addConstraint(_JCLayoutConstraintMake(leftButton, .left, .equal, contentView, .left, 15))
- addConstraint(_JCLayoutConstraintMake(leftButton, .right, .equal, contentView, .centerX, -12.5))
- addConstraint(_JCLayoutConstraintMake(leftButton, .top, .equal, contentView, .top))
- addConstraint(_JCLayoutConstraintMake(leftButton, .bottom, .equal, contentView, .bottom))
-
- addConstraint(_JCLayoutConstraintMake(rightButton, .left, .equal, contentView, .centerX, 12.5))
- addConstraint(_JCLayoutConstraintMake(rightButton, .right, .equal, contentView, .right, -15))
- addConstraint(_JCLayoutConstraintMake(rightButton, .top, .equal, contentView, .top))
- addConstraint(_JCLayoutConstraintMake(rightButton, .bottom, .equal, contentView, .bottom))
- }
-
- //MARK: - click func
- func _clickLeftButton(_ sender: UIButton) {
- delegate?.doubleButtonCell?(clickLeftButton: sender)
- }
-
- func _clickRightButton(_ sender: UIButton) {
- delegate?.doubleButtonCell?(clickRightButton: sender)
- }
- }
|