想做一个btn 点击飘一个红色+1 然后消失, 就自己写了个函数实现 如下
~
extension UIView{
func driftingText(text:String,color:UIColor = UIColor.redColor()){
let textNum:CGFloat = CGFloat(text.characters.count)
UIFont.systemFontSize()
let textLabel = UILabel(frame: CGRect(x: 0, y: 0, width: UIFont.systemFontSize()*textNum, height: 20))
textLabel.text = text
textLabel.textColor = color
textLabel.x = self.bounds.width/2
textLabel.y = 0
self.addSubview(textLabel)
UIView.transitionWithView(textLabel, duration: 0.5, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in
textLabel.y = -20
textLabel.alpha = 0
}) { (bool) -> Void in
// 完成动画删除
textLabel.removeFromSuperview()
}
}
}
~