zoukankan      html  css  js  c++  java
  • ios自定义checkbox

    //Author:smilelance

    //From:http://blog.csdn.net/smilelance


    #import <UIKit/UIKit.h>


    @interface PDECheckBox : UIButton

    {

        BOOL isChecked;

    }


    - (id)initWithCenter:(CGPoint)center;

    - (BOOL)isChecked;

    - (void)setCheckState:(BOOL)checked;

    - (void)switchCheckState;

    @end


    #import "PDECheckBox.h"


    #define IMAGE_CHECKED @"checkbox_gray_sel.png"

    #define IMAGE_UNCHECKED @"checkbox_gray.png"


    @implementation PDECheckBox



    - (id)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            // Initialization code

        }

        return self;

    }


    - (id)initWithCenter:(CGPoint)center

    {

    //    UIImage *imgChecked = [UIImage imageNamed:IMAGE_CHECKED];

        UIImage *imgUnChecked = [UIImageimageNamed:IMAGE_UNCHECKED];

        CGSize size = imgUnChecked.size;

        CGRect frame = CGRectMake(center.x-size.width/2, center.y-size.height/2

                                  size.width, size.height);

        self = [super initWithFrame:frame];

        if (self) {

            // Initialization code

            [selfsetImage:imgUnChecked forState:UIControlStateNormal];

            isChecked = NO;

            [selfaddTarget:selfaction:@selector(switchCheckState)forControlEvents:UIControlEventTouchUpInside];

        }

        return self;

    }


    - (BOOL)isChecked

    {

        returnisChecked;

    }

    - (void)switchCheckState

    {

        [selfsetCheckState:!isChecked];

    }

    - (void)setCheckState:(BOOL)checked

    {

        if (checked != isChecked) {

            isChecked = checked;

            if (isChecked) {

                [selfsetImage:[UIImageimageNamed:IMAGE_CHECKED]forState:UIControlStateNormal];

            }else {

                [selfsetImage:[UIImageimageNamed:IMAGE_UNCHECKED]forState:UIControlStateNormal];

            }

        }

    }


    @end


  • 相关阅读:
    python—内置函数-filter,map,reduce
    python—模块-练习
    python—模块-re正则表达式
    python—模块-logging
    python—模块-subprocess
    python—模块-hashlib加密
    python—模块-configparser
    SpringBoot结合设计模式(观察者模式、策略模式)- 个人记录
    Spring事务-随笔
    Servlet、Tomcat、SpringMVC-整理-随笔
  • 原文地址:https://www.cnblogs.com/secbook/p/2655371.html
Copyright © 2011-2022 走看看