日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[翻译] MZTimerLabel 用作秒表或者倒计时

發布時間:2024/5/8 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [翻译] MZTimerLabel 用作秒表或者倒计时 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MZTimerLabel?用作秒表或者倒計時

https://github.com/mineschan/MZTimerLabel

A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.

一個基于UILabel好用的倒計時或者秒表的類。

Purpose(目的

MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple Clock App with just?2 lines of code. MZTimerLabel also provides delegate method for you to define the action when the timer finished.

MZTimerLabel是一個UILabel的子類,兩行代碼就可以顯示秒表效果。它提供代理來幫助你處理倒計時結束后的事件處理。

Auther:?MineS Chan

Remark: This is my first iOS plugin project on github, please accept my apologize if any bad coding.

Requirements(要求

  • ARC
  • iOS 5.0+

Installations(安裝

Manual

  • Download or clone MZTimerLabel, add?MZTimerLabel.h?and?MZTimerLabel.m?souce files into your project.將文件夾MZTimerLabel拖入你的工程當中
  • #import "MZTimerLabel.h"?whereever you need it.引入頭文件
  • CocoaPods

    (Unformilar with?CocoaPods?yet? It's a dependency management tool for iOS and Mac, check it out!)

  • Add?pod 'MZTimerLabel', '~> 0.4.1'?to your podfiles
  • Easy Example(簡單示例

    To use MZTimerLabel as a stopwatch and counter, you need only?2 lines.

    使用MZTimerLabel作為秒表或者定時器,你只需兩行代碼。

    MZTimerLabel *stopwatch = [[MZTimerLabel alloc] initWithLabel:aUILabel];[stopwatch start];

    Easy? If you are looking for a timer, things is just similar.

    so easy.如果你想使用一個定時器,一樣的。

    MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer];[timer setCountDownTime:60];[timer start];

    Now the timer will start counting from 60 to 0 ;)

    現在,時間就會從60到0了。

    Custom Appearance(自定義外觀

    As MZTimerLabel is a UILabel subclass, you can directly allocate it as a normal UILabel and customizetimeLabel?property just like usual.

    由于MZTimerLabel是UILabel的子類,你可以直接alloc出來作為一個UILabel然后定制timeLabel屬性即可。

    MZTimerLabel *redStopwatch = [[MZTimerLabel alloc] init];redStopwatch.frame = CGRectMake(100,50,100,20);redStopwatch.timeLabel.font = [UIFont systemFontOfSize:20.0f];redStopwatch.timeLabel.textColor = [UIColor redColor];[self.view addSubview:redStopwatch];[redStopwatch start];

    MZTimerLabel uses?00:00:00 (HH:mm:ss)?as time format, if you prefer using another format such as including milliseconds.Your can set your time format like below.

    MZTimerLabel使用 00:00:00 作為時間格式,如果你想使用毫秒顯示。你可以設置成下面的方式。

    timerExample4.timeFormat = @"HH:mm:ss SS";

    Control the timer(控制定時器

    You can start,pause,reset your timer with your custom control, set your control up and call these methods:

    你可以開始,暫停,重設你的定時器:

    -(void)start; -(void)pause; -(void)reset;

    And you control the time at the begining or during runtime with these methods

    在定時器開始時或者是啟動后修改:

    -(void)setCountDownTime:(NSTimeInterval)time; -(void)setStopWatchTime:(NSTimeInterval)time; -(void)setCountDownToDate:(NSDate*)date; -(void)addTimeCountedByTime:(NSTimeInterval)timeToAdd;

    Timer Finish Handling(倒計時結束后的控制

    Usually when you need a timer, you need to deal with it after it finished counting. Following are 2 examples showing how to do it using?delegate?and?block?methods.

    通常你要定時器,是為了結束后能處理一下時間。下面有兩個例子來,一個用代理實現,一個用block來實現。

    Delegate

    First, set the delegate of the timer label.

    首先設置代理

    timer.delegate = self;

    And then implement?MZTimerLabelDelegate?protocol in your dedicated class

    然后實現 MZTimerLabelDelegate 協議

    @interface ViewController : UIViewController<MZTimerLabelDelegate>

    Finally, implement the delegate method?timerLabel:finshedCountDownTimerWithTimeWithTime:

    最后,實現代理方法?timerLabel:finshedCountDownTimerWithTimeWithTime:

    -(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime{//time is up, what should I do master?}

    Blocks

    Block is a very convenient way to handle the callbacks, MZTimerLabel makes your life even easier.

    使用block非常便利,MZTimerLabel讓你無比輕松。

    MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer];[timer3 setCountDownTime:60]; [timer startWithEndingBlock:^(NSTimeInterval countTime) {//oh my god it's awesome!!}];

    ?

    ?

    ?

    總結

    以上是生活随笔為你收集整理的[翻译] MZTimerLabel 用作秒表或者倒计时的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。