diff --git a/OrderScheduling/ReviewFailed/ViewController/ReviewFailedController.swift b/OrderScheduling/ReviewFailed/ViewController/ReviewFailedController.swift index 5777c86..97b70cb 100644 --- a/OrderScheduling/ReviewFailed/ViewController/ReviewFailedController.swift +++ b/OrderScheduling/ReviewFailed/ViewController/ReviewFailedController.swift @@ -438,6 +438,24 @@ open class ReviewFailedView : DDView { } } +// Gradient button subclass for ReviewFailedCell buttons +public final class DDGradientButton: DDButton { + public override class var layerClass: AnyClass { CAGradientLayer.self } + var gradientLayer: CAGradientLayer { return self.layer as! CAGradientLayer } + + func configureGradient(start: CGPoint = CGPoint(x: 0, y: 0), + end: CGPoint = CGPoint(x: 1, y: 1), + locations: [NSNumber] = [0.0, 1.0], + colors: [CGColor]) { + gradientLayer.startPoint = start + gradientLayer.endPoint = end + gradientLayer.locations = locations + gradientLayer.colors = colors + gradientLayer.masksToBounds = true + gradientLayer.needsDisplayOnBoundsChange = true + } +} + open class ReviewFailedCell : DDTableViewCell { public let radiusView : DDView public let typeLabel : DDLabel @@ -447,28 +465,8 @@ open class ReviewFailedCell : DDTableViewCell { public let descLabel : DDLabel public let dateLabel : DDLabel public let stackView : UIStackView - public let appealButton : DDButton - public var appealLayer : CAGradientLayer = { - var layer = CAGradientLayer.init() - layer.startPoint = CGPoint(x: 0, y: 0) - layer.endPoint = CGPoint(x: 1, y: 1) - layer.locations = [0.0,1.0] - layer.colors = [UIColor.hex("FF5A2C").cgColor,UIColor.hex("FE9D4D").cgColor] - layer.cornerRadius = auto(4) - layer.masksToBounds = true - return layer - }() - public let additionalButton : DDButton - public var additionalLayer : CAGradientLayer = { - var layer = CAGradientLayer.init() - layer.startPoint = CGPoint(x: 0, y: 0) - layer.endPoint = CGPoint(x: 1, y: 1) - layer.locations = [0.0,1.0] - layer.colors = [UIColor.hex("FF5A2C").cgColor,UIColor.hex("FE9D4D").cgColor] - layer.cornerRadius = auto(4) - layer.masksToBounds = true - return layer - }() + public let appealButton : DDGradientButton + public let additionalButton : DDGradientButton public var disposeBag = DisposeBag() public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { @@ -480,8 +478,8 @@ open class ReviewFailedCell : DDTableViewCell { descLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(13)), textColor: .hex("FF8F37")) dateLabel = DDLabel.dd_init(withText: "", font: .regularFont(auto(12)), textColor: .hex("000000").alpha(0.55)) stackView = UIStackView() - additionalButton = DDButton.dd_initCustom() - appealButton = DDButton.dd_initCustom() + additionalButton = DDGradientButton() + appealButton = DDGradientButton() super.init(style: style, reuseIdentifier: reuseIdentifier) backgroundColor = .hex("F4F5F7") @@ -513,16 +511,16 @@ open class ReviewFailedCell : DDTableViewCell { appealButton.layer.cornerRadius = auto(4) appealButton.layer.masksToBounds = true appealButton.contentEdgeInsets = UIEdgeInsets(top: auto(6), left: auto(12), bottom: auto(6), right: auto(12)) + appealButton.configureGradient(colors: [UIColor.hex("FF5A2C").cgColor, UIColor.hex("FE9D4D").cgColor]) stackView.addArrangedSubview(appealButton) - appealButton.layer.insertSublayer(appealLayer, at: 0) additionalButton.setTitle("补充", for: .normal) additionalButton.setTitleColor(.white, for: .normal) additionalButton.titleLabel?.font = .mediumFont(auto(13)) additionalButton.layer.cornerRadius = auto(4) additionalButton.layer.masksToBounds = true additionalButton.contentEdgeInsets = UIEdgeInsets(top: auto(6), left: auto(12), bottom: auto(6), right: auto(12)) + additionalButton.configureGradient(colors: [UIColor.hex("FF5A2C").cgColor, UIColor.hex("FE9D4D").cgColor]) stackView.addArrangedSubview(additionalButton) - additionalButton.layer.insertSublayer(additionalLayer, at: 0) radiusView.snp.makeConstraints { make in make.left.top.equalTo(auto(10)) @@ -584,8 +582,5 @@ open class ReviewFailedCell : DDTableViewCell { open override func layoutSubviews() { super.layoutSubviews() - // Match gradient layers to button bounds - appealLayer.frame = appealButton.bounds - additionalLayer.frame = additionalButton.bounds } }