CNLiveShopCouponCreateBottomView.swift 2.33 KB
//
//  CNLiveShopCouponCreateBottomView.swift
//  metaCode
//
//  Created by zx on 2023/12/12.
//

import Foundation
import SnapKit
protocol CNLiveShopCouponButtonClickDelegate:NSObjectProtocol{
    /// 单点
    /// @param gestureView 手势视图
    /// @param recognizer 手势
    func selectedItemButton(section:Int)

}

class CNLiveShopCouponCreateBottomView:UIView{
    /// 代理
    weak var delegate:CNLiveShopCouponButtonClickDelegate?
    
    lazy var cancelsBtn: UIButton = {
        
        let button = UIButton(type: .custom)
        button.backgroundColor = UIColor.white
        button.setTitleColor(  HexColor("#3A3A3A"), for: .normal)
        button.setTitle("取消", for: .normal)
        button.tag = 1000
        button.addTarget(self, action: #selector(selectAction), for: .touchUpInside)
        return button
    }()
    
    lazy var saveBtn: UIButton = {
        let  saveBtn = UIButton(type: .custom)
        saveBtn.tag = 1001
        let gradientLayer = CAGradientLayer()

        gradientLayer.locations = [0, 1]
        gradientLayer.startPoint = CGPoint(x: 0.88, y: 0.11)
        gradientLayer.endPoint = CGPoint(x: 0.28, y: 0.81)

        let color1 = HexColor("#7ED785")!.cgColor
        let color2 = HexColor("#64C367")!.cgColor
        gradientLayer.colors = [color1, color2]

        gradientLayer.frame = CGRect(x: 0, y: 0, width: 245, height: 50)
        saveBtn.layer.addSublayer(gradientLayer)
        saveBtn.setTitle("保存", for: .normal)
        saveBtn.setTitleColor(.white, for: .normal)
        
        saveBtn.addTarget(self, action: #selector(selectAction), for: .touchUpInside)
        return saveBtn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
            
        self.addSubview(self.cancelsBtn)
        self.addSubview(self.saveBtn)
        self.saveBtn.snp.makeConstraints { make in
            make.top.right.bottom.equalTo(self)
            make.width.equalTo(245)
        }
        self.cancelsBtn.snp.makeConstraints { make in
            make.left.top.bottom.equalTo(self)
            make.right.equalTo(self.saveBtn.snp.left)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func selectAction(_ sender: UIButton) {
        self.delegate?.selectedItemButton(section: sender.tag - 1000)
    }
}