美文网首页
动态下划线和字体动态缩放

动态下划线和字体动态缩放

作者: CimonsLee | 来源:发表于2018-12-19 15:38 被阅读7次

/// 增加动态下划线
func addDynamicLine(baseView: UIView, lineAdd: UIView,lineColor: UIColor) {

baseView.addSubview(lineAdd)
lineAdd.backgroundColor = lineColor
lineAdd.snp.makeConstraints { (make) in
    make.leading.equalTo(baseView).offset(0)
    make.trailing.equalTo(baseView).offset(0)
    make.bottom.equalTo(baseView).offset(0)
    make.height.equalTo(1)
}

let lineTran = CGAffineTransform(translationX: 0, y: 0)
lineAdd.transform = lineTran.scaledBy(x: 0, y: 1)

}

/// 下划线动态显示,文字动态缩放
func showDynamicLineAndScaleLabel(line: UIView,label: UILabel,widthLabel: CGFloat) {

UIView.animate(withDuration: 0.2) {
    
    let trans = CGAffineTransform(translationX: -(8+widthLabel/4), y: -24)
    label.transform = trans.scaledBy(x: 0.5, y: 0.5)
    label.textColor = UIColor(hex: 0xFDAE1B)
    
    let lineTran = CGAffineTransform(translationX: 0, y: 0)
    line.transform = lineTran.scaledBy(x: 1, y: 1)
    
}

}

/// 下划线隐藏,文字动态扩大
func hiddenDynamicLineAndScaleLabel(line: UIView,label: UILabel) {

UIView.animate(withDuration: 0.2) {
    
    
    label.transform = CGAffineTransform.identity
    label.textColor = UIColor(hex: 0x808795)
    
    let lineTran = CGAffineTransform(translationX: 0, y: 0)
    /// 调为零消失很快,看不到消失效果
    line.transform = lineTran.scaledBy(x: 0.00000001, y: 1)
}

}

相关文章

网友评论

      本文标题:动态下划线和字体动态缩放

      本文链接:https://www.haomeiwen.com/subject/bzruoxtx.html