优三帝同学

上善若水,人淡如菊

嗨,我是优三帝 (@onevcat),一名 Unity 开发者。


欢迎访问我的博客~

VVBorderTimer

GitHub 链接: https://github.com/onevcat/VVBorderTimerView

是什么

  • VVBorderTimer是UIView的子类
  • 它为UIView提供使用边界进行倒计时的效果
  • 边框角落的半径和线宽在运行时可调
  • 倒计时是有颜色渐变效果

What’s this

  • VVBorderTimer is a subclass of UIView.
  • It provides an counting down effect using the view’s border.
  • The radius of round corners and line width are configurable in runtime.
  • There is also a color transition effect during the counting.

怎么用

  • 将VVBorderTimerView.h和VVBorderTimerView.m导入您的工程。请根据您的情况选择使用ARC版本或非ARC版本
  • 分配并初始化一个VVBorderTimerView. 设置其背景颜色
    VVBorderTimerView *btv = [[VVBorderTimerView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)];
    //为计时器设置背景颜色
    btv.backgroundColor = [UIColor clearColor];
    
    1. 配置计时器属性,如: 颜色(可选), 总时间和delegate.
      //上边界为绿色
      UIColor *color0 = [UIColor greenColor];
      //右边黄色
      UIColor *color1 = [UIColor yellowColor];
      //下边橙色
      UIColor *color2 = [UIColor colorWithRed:1.0 green:140.0/255.0 blue:16.0/255.0 alpha:1.0];
      //左边红色
      UIColor *color3 = [UIColor redColor];
      //为计时器指定颜色. 不同颜色将在转角处发生渐变.
      //如果您没有指定颜色,或者指定其为nil(btv.colors = nil),所有边将默认使用黑色
      btv.colors = [NSArray arrayWithObjects:color0,color1,color2,color3,nil];
      //为计时器设定总时间
      btv.totalTime = 10;
      //为计时器设定delegate
      btv.delegate = self;
      
    2. 实现计时器的delegate
      //转角半径(0 代表矩形)
      -(float) cornerRadius:(VVBorderTimerView *)requestor
      { return 30;
      }
      //计时器线宽
      -(float) lineWidth:(VVBorderTimerView *)requestor
      { return 10;
      }
      //当计时器停止时,该方法被调用
      -(void) timerViewDidFinishedTiming:(VVBorderTimerView *)aTimerView
      { //do something
      }
      
    3. 将计时器加入您的viewController的view,并使用 -(void)start 开始计时
      [self.view addSubview:btv];
      [btv start];
      

如果您使用的是非ARC,请不要忘记在将计时器加入view结构后释放它。可能您需要保留一个指向该计时器的指针,以便在即使结束后将其移除 在GitHub网站的这个页面上有一个简单的demo供您参考,如果您感兴趣,可以关注或者分支该项目。祝您好运~

How to use

  1. Import VVBorderTimerView.h and VVBorderTimerView.m to your project. Select either ARC version or non-ARC version for your situation.
  2. Alloc and init a VVBorderTimerView. Set its background color.
    VVBorderTimerView *btv = [[VVBorderTimerView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)];
    //Specify a background color for the timer
    btv.backgroundColor = [UIColor clearColor];
    
  3. Set the properties for the timer: colors(optional), totalTime and delegate.
    //Top border will be green
    UIColor *color0 = [UIColor greenColor];
    //Right border yellow
    UIColor *color1 = [UIColor yellowColor];
    //Buttom border orange
    UIColor *color2 = [UIColor colorWithRed:1.0 green:140.0/255.0 blue:16.0/255.0 alpha:1.0];
    //Left border red
    UIColor *color3 = [UIColor redColor];
    //Set the colors for the timer. Color transition will be occured in the corner.
    //If your DID NOT specify the colors or specify it to nil(btv.colors = nil), default black color for all edge will be used.
    btv.colors = [NSArray arrayWithObjects:color0,color1,color2,color3,nil];
    //Set the total time the timer should count in second
    btv.totalTime = 10;
    //Set the delegate for the timer
    btv.delegate = self;
    
  4. Implement the timer’s delegate
    //Corner radius for a timer(0 means rectangle)
    -(float) cornerRadius:(VVBorderTimerView *)requestor
    { return 30;
    }
    //Line width for a timer
    -(float) lineWidth:(VVBorderTimerView *)requestor
    { return 10;
    }
    //When the timer stopped, this method will be called
    -(void) timerViewDidFinishedTiming:(VVBorderTimerView *)aTimerView
    { //do something
    }
    
  5. Add it to your viewController’s view and then start the timer using -(void)start
    [self.view addSubview:btv];
    [btv start];
    

DO NOT forget to release the timer after it is added to the view’s hierarchy if you use non-ARC. You may want to keey a pointer to the timer, so you can remove it from superview when it stops. You can also find a demo in the github page here. You can watch and fork it if you are intrested in it. Enjoy!

Lisence

VVBorderTimer is Copyright © 2011 Wei Wang(onevcat), All Rights Reserved, All Wrongs Revenged. Released under the New BSD Licence.

  • https://github.com/onevcat/VVBorderTimerView/ BSD license follows (http://www.opensource.org/licenses/bsd-license.php) Copyright (c) 2011 Wei Wang(onevcat) All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBU -TORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Buy me a coffeeBuy me a coffee
最近的文章

AHRP 2013 内部推荐机会

2013秋季项目内推已经结束。如果打算参加的话,可以关注9月份陆续开始的宣讲会和AHRP官方网站的一些信息。谢谢大家对AHRP项目和我的blog的关注~~AHRP新一年的秋季项目即将开始,2012春季项目中博主内推的童鞋中有2人最终拿到了offer,而2013秋季依然我有机会作为内定者为大家进行内推。如果有对该项目感兴趣的童鞋欢迎给我邮件或留言咨询最新情况。此次内推5月26日就将截止,AHRP秋季项目将在6月初和被内推者先行联系,现在申请可以先人一步,将对您求职路上占据主动有很大帮助!~~...…

胡言乱语集继续阅读
更早的文章

凑热闹,谈密码,Challenge-Response密码验证

CSDN的密码事件闹得沸沸扬扬,600万用户数据的泄露应该是中国互联网历史上最严重的帐号信息泄露事件。让人不可思议的是,2009年4月之前的用户密码居然是以明文存储。使用明文存储密码本身就是一件相当扯淡的事情,而当这种事情发生在以程序员为主要客户的大型网站上,真是让人哭笑不得。之后又陆续爆出人人、多玩以及各种知名网站的账户信息泄露的消息,虽然还未确知真伪,但也很是让人揪心。而“不能明文保存密码”这一个初级中的初级的错误之所以会在中国这篇神奇的土地上一次又一次的出现,我认为是与中国的网络审查...…

南箕北斗集继续阅读