Swift and swiftcode
Swift-a hybrid progress bar is achieved by adding UILabel
Effect
Source code
Https://github.com/YouXianMing/Swift-Animations
/// MixedColorProgressViewController. swift // Swift-Animations // Created by YouXianMing on 16/8/21. // Copyright©2016 YouXianMing. All rights reserved. // import UIKitclass MixedColorProgressViewController: NormalTitleViewController {private var upView: UIView! Private var upLabel: UILabel! Private var downView: UIView! Private var downLabel: UILabel! Private var timer: GCDTimer! = GCDTimer (inQueue: GCDQueue. mainQueue) override func setup () {super. setup () downView = UIView (frame: CGRectMake (0, 0,220, 17) downView. center = (contentView ?. MiddlePoint )! DownView. layer. cornerRadius = 2 downView. backgroundColor = UIColor. whiteColor () downView. layer. masksToBounds = true contentView ?. AddSubview (downView) downLabel = UILabel (frame: downView. bounds) downLabel. font = UIFont. helveticaNeueThin (12.0) downLabel. text = "YouXianMing-iOS Programmer" downLabel. textColor = UIColor. redColor () downLabel. textAlignment =. center downView. layer. borderWidth = 0.5 downView. layer. borderColor = UIColor. redColor (). CGColor downView. addSubview (downLabel) upView = UIView (frame: CGRectMake (0, 0,220, 17) upView. center = (contentView ?. MiddlePoint )! UpView. layer. cornerRadius = 2 upView. backgroundColor = UIColor. redColor () upView. layer. masksToBounds = true contentView ?. AddSubview (upView) upLabel = UILabel (frame: upView. bounds) upLabel. font = UIFont. helveticaNeueThin (12.0) upLabel. text = "YouXianMing-iOS Programmer" upLabel. textColor = UIColor. whiteColor () upLabel. textAlignment =. center upView. addSubview (upLabel) weak var wself = self timer. event ({UIView. animateWithDuration (0.5, delay: 0, usingSpringWithDamping: 3, initialSpringVelocity: 0, options :. curveEase InOut, animations: {wself ?. UpView. width = CGFloat (arc4random () % 220)}, completion: nil)}, timeIntervalWithSeconds: 1, delayWithSeconds: 1) timer. start ()}}