UIButton:|UIButton: 巧妙封装截获响应

前言:
重新写个APP 很多东西都要重新来写(之前懒没有将控件剥离出来,现在也懒得去找以前的项目,所以就一波流----重写吧??)
这里需要实现一个常用的短信验证码倒计时功能,这玩意儿很多小伙伴都重写过吧,所以今天在这里封装一个专门用来做倒计时的按钮。(老鸟不喜勿喷)
操作:
这是一些比较简单但是繁琐的小东西主要用到下面这个函数,以及GCD
- (void)sendAction:(SEL)action
to:(id)target
forEvent:(UIEvent *)event;
这个函数链接:sendAction:to:forEvent:
文档描述为:
This method takes the provided information and forwards it to the singleton UIApplicationobject for dispatching. If a valid target object was supplied, the app calls the action method on that target object. If the target object is nil, the app searches the responder chain for an object that defines the method.
Subclasses may override this method and use it to observe or modify the action dispatching behavior. Implementations should call super when they want to continue with the execution of the action method.
这里的用处就是当Button被点击了之后会调用这个函数来调用Button的响应方法。
所以在这里我将验证码倒计时的逻辑就添加在这个函数调用里,实现带倒计时功能的自定义Button 以后有项目了随便拿来用还不用找代码。
核心代码:


UIButton:|UIButton: 巧妙封装截获响应
文章图片
核心代码 【UIButton:|UIButton: 巧妙封装截获响应】这样就巧妙的实现了Button封装。而且还避免了使用UIView来自定义一个Button的杂乱代码(反正我看着不怎么舒服)

    推荐阅读