Swift中通過疊加UILabel實(shí)現(xiàn)混合進(jìn)度條的方法
更新時間:2016年08月22日 09:34:52 作者:YouXianMing
這篇文章主要介紹了Swift中通過疊加UILabel實(shí)現(xiàn)混合進(jìn)度條的方法的相關(guān)資料,需要的朋友可以參考下
先給大家展示下效果圖,如果大家感覺還不錯,請參考實(shí)現(xiàn)代碼。
效果圖如下所示:


源碼
https://github.com/YouXianMing/Swift-Animations
//
// MixedColorProgressViewController.swift
// Swift-Animations
//
// Created by YouXianMing on 16/8/21.
// Copyright © 2016年 YouXianMing. All rights reserved.
//
import UIKit
class 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: .CurveEaseInOut, animations: {
wself?.upView.width = CGFloat(arc4random() % 220)
}, completion: nil)
}, timeIntervalWithSeconds: 1, delayWithSeconds: 1)
timer.start()
}
}
以上所述是小編給大家介紹的Swift中通過疊加UILabel實(shí)現(xiàn)混合進(jìn)度條的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
- iOS開發(fā)中使用UILabel設(shè)置字體的相關(guān)技巧小結(jié)
- iOS長按UIlabel實(shí)現(xiàn)可復(fù)制功能
- iOS應(yīng)用中UILabel文字顯示效果的常用設(shè)置總結(jié)
- iOS App開發(fā)中修改UILabel默認(rèn)字體的方法
- iOS App中UILabel的自定義及在Auto Layout中的使用
- iOS開發(fā)筆記--詳解UILabel的相關(guān)屬性設(shè)置
- iOS中UILabel text兩邊對齊的實(shí)現(xiàn)代碼
- Swift 3.0將UILabel數(shù)字顏色設(shè)置為紅色的方法
相關(guān)文章
swift中AnyObject和Any的介紹與區(qū)別詳解
雖然使用swift開發(fā)了一段時間,但是感覺對一些基礎(chǔ)的東西了解不是比較透徹,在查詢了許多資料以后還是打算自己動手記錄一下,下面這篇文章主要給大家介紹了關(guān)于swift中AnyObject和Any的介紹與區(qū)別的相關(guān)資料,需要的朋友可以參考下。2017-12-12
Swift 3.0基礎(chǔ)學(xué)習(xí)之閉包
Swift引進(jìn)了閉包的概念,這個與object-c的block類似,使用過block的話都知道有多方便,所以開始學(xué)Swift,先要把閉包學(xué)會,后面使用會很頻繁。下面這篇文章主要介紹了Swift 3.0基礎(chǔ)學(xué)習(xí)之閉包的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03
倉庫模式及其在Swift?項(xiàng)目中的應(yīng)用詳解
這篇文章主要為大家介紹了倉庫模式及其在Swift?項(xiàng)目中的應(yīng)用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01

