zoukankan      html  css  js  c++  java
  • 定制个性化按钮

    定制个性化按钮

    效果

    说明

    通过捕捉一个按钮不同状态的值来定制我们自己的按钮动画,本人仅仅提供了实现的抽象基类以及一个简单的示例,剩下的需要你根据自己的想象力创造了.

    源码

    https://github.com/YouXianMing/UI-Component-Collection

    //
    //  BaseControl.h
    //  BaseButton
    //
    //  Created by YouXianMing on 15/8/27.
    //  Copyright (c) 2015年 YouXianMing. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface BaseControl : UIView
    
    /**
     *  ========================
     *  = override by subclass =
     *  ========================
     *
     *  触发点击事件
     */
    - (void)touchEvent;
    
    /**
     *  ========================
     *  = override by subclass =
     *  ========================
     *
     *  拖拽到rect外面触发的事件
     */
    - (void)touchDragExit;
    
    /**
     *  ========================
     *  = override by subclass =
     *  ========================
     *
     *  点击事件开始
     */
    - (void)touchBegin;
    
    @end
    //
    //  BaseControl.m
    //  BaseButton
    //
    //  Created by YouXianMing on 15/8/27.
    //  Copyright (c) 2015年 YouXianMing. All rights reserved.
    //
    
    #import "BaseControl.h"
    
    @interface BaseControl ()
    
    @property (nonatomic, strong) UIButton *button;
    
    @end
    
    @implementation BaseControl
    
    - (instancetype)initWithFrame:(CGRect)frame {
        
        self = [super initWithFrame:frame];
        if (self) {
            
            [self baseControlSetup];
        }
        
        return self;
    }
    
    - (void)baseControlSetup {
        
        _button = [[UIButton alloc] initWithFrame:self.bounds];
        [self addSubview:_button];
        
        // 开始点击
        [_button addTarget:self
                    action:@selector(touchBegin)
          forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter];
        
        // 拖拽到rect外面
        [_button addTarget:self
                    action:@selector(touchDragExit)
          forControlEvents:UIControlEventTouchDragExit];
        
        // 触发事件
        [_button addTarget:self
                    action:@selector(touchEvent)
          forControlEvents:UIControlEventTouchUpInside];
    }
    
    - (void)touchEvent {
        
        [NSException raise:NSInternalInconsistencyException
                    format:@"对不起,您不能直接调用 '%@ %d' 中的方法 '%@',您需要通过继承其子类,在子类中重载该方法",
         [NSString stringWithUTF8String:__FILE__].lastPathComponent, __LINE__, NSStringFromSelector(_cmd)];
    }
    
    - (void)touchDragExit {
        
        [NSException raise:NSInternalInconsistencyException
                    format:@"对不起,您不能直接调用 '%@ %d' 中的方法 '%@',您需要通过继承其子类,在子类中重载该方法",
         [NSString stringWithUTF8String:__FILE__].lastPathComponent, __LINE__, NSStringFromSelector(_cmd)];
    }
    
    - (void)touchBegin {
        
        [NSException raise:NSInternalInconsistencyException
                    format:@"对不起,您不能直接调用 '%@ %d' 中的方法 '%@',您需要通过继承其子类,在子类中重载该方法",
         [NSString stringWithUTF8String:__FILE__].lastPathComponent, __LINE__, NSStringFromSelector(_cmd)];
    }
    
    @end

    细节

  • 相关阅读:
    linux 统计文件行数的命令效率
    使用mysqldump导入不成功解决方法
    shell中获取当前目录
    shell读取文档中的命令并执行
    读取文件,文件内容包含空格Tab和回车提取想要的数据
    ls命令中的--time-style使用
    Vmware中网卡未启用,安装系统后再启用网卡,eth0如何设置
    lvm逻辑卷扩展方法
    linux小技巧 一
    解决ARCGIS10.2与VS2013不兼容
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4764552.html
Copyright © 2011-2022 走看看