import UIKit
class LineLabel: UILabel {
override func awakeFromNib() {
let priceString = NSMutableAttributedString.init(string: self.text!)
priceString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSNumber.init(value: 1), range: NSRange(location: 0, length: priceString.length))
self.attributedText = priceString
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
//
// BottonLineBtn.swift
// BimDog
//
// Created by Chengzhe Bu on 2017/11/9.
// Copyright © 2017年 Bim. All rights reserved.
//
import UIKit
class BottonLineBtn: UIButton {
var lineColor: UIColor!
internal func setColor(color:UIColor) {
if lineColor == nil {
lineColor = UIColor.white
}
lineColor = color.copy() as! UIColor
self.setNeedsDisplay()
}
override func draw(_ rect: CGRect) {
let textRect: CGRect = self.titleLabel!.frame
let contextRef: CGContext = UIGraphicsGetCurrentContext()!
let descender: CGFloat = self.titleLabel!.font.descender
contextRef.setStrokeColor(UIColor.white.cgColor);
contextRef.move(to: CGPoint.init(x: textRect.origin.x, y: textRect.origin.y + textRect.size.height + descender + 1))
contextRef.addLine(to: CGPoint.init(x: textRect.origin.x + textRect.size.width, y: textRect.origin.y + textRect.size.height + descender + 1))
contextRef.closePath()
contextRef.strokePath();
}
}