国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

I-OS開發(fā)自定義CheckBox控件

2019-11-02 14:43:01
字體:
供稿:網(wǎng)友

  IOS本身沒有系統(tǒng)的CheckBox組件,但是實(shí)際開發(fā)中會(huì)經(jīng)常用到,所以專門寫了一個(gè)CheckBox控件,直接上代碼

  效果圖:

IOS開發(fā)自定義CheckBox控件 電腦高手

  UICheckBoxButton.h文件如下:

  #import

  #import "Common.h"

  @interface UICheckBoxButton : UIControl

  {

  UILabel *label;

  UIImageView *icon;

  BOOL checked;

  id delegate;

  }

  @property (retain, nonatomic) id delegate;

  @property (retain, nonatomic) UILabel *label;

  @property (retain, nonatomic) UIImageView *icon;

  -(BOOL)isChecked;

  -(void)setChecked: (BOOL)flag;

  @end

  UICheckBoxButton.m文件如下:

  #import "UICheckBoxButton.h"

  @implementation UICheckBoxButton

  @synthesize label,icon,delegate;

  - (id)initWithFrame:(CGRect)frame {

  if ( self = [super initWithFrame: frame])

  {

  icon =[[UIImageView alloc] initWithFrame: CGRectMake (0, 0, frame.size.height, frame.size.height)];

  [self setChecked:NO];

  [self addSubview: icon];

  label =[[UILabel alloc] initWithFrame: CGRectMake(icon.frame.size.width + 7, 0,

  frame.size.width - icon.frame.size.width - 10,

  frame.size.height)];

  label.backgroundColor =[UIColor clearColor];

  label.textAlignment = UITextAlignmentLeft;

  [self addSubview:label];

  [self addTarget:self action:@selector(clicked) forControlEvents: UIControlEventTouchUpInside];

  }

  return self;

  }

  -(BOOL)isChecked {

  return checked;

  }

  -(void)setChecked: (BOOL)flag {

  if (flag != checked)

  {

  checked = flag;

  }

  if (checked)

  {

  [icon setImage: [UIImage imageNamed:@"checkBoxSelect.png"]];

  }

  else

  {

  [icon setImage: [UIImage imageNamed:@"checkBoxNoSelect.png"]];

  }

  }

  -(void)clicked {

  [self setChecked: !checked];

  if (delegate != nil)

  {

  SEL sel = NSSelectorFromString (@"checkButtonClicked");

  if ([delegate respondsToSelector: sel])

  {

  [delegate performSelector: sel];

  }

  }

  }

  -(void)dealloc {

  delegate = nil;

  [label release];

  [icon release];

  [super dealloc];

  }

  @end

  使用方法:

  UICheckBoxButton *checkBoxButton = [[ UICheckBoxButton alloc] initWithFrame: CGRectMake(30, 50, 220, 25)];

  checkBoxButton.delegate = self.delegate;

  checkBoxButton.label.text = [Common getTextByTag:@"noCostPrompt"];

  checkBoxButton.label.textColor = [Common

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新巴尔虎右旗| 安龙县| 资兴市| 阳原县| 宁远县| 陵水| 集贤县| 永春县| 江油市| 长顺县| 阜阳市| 全南县| 漳平市| 北碚区| 宁德市| 东乌珠穆沁旗| 蓬溪县| 亳州市| 长阳| 乡城县| 乾安县| 社旗县| 永德县| 兴隆县| 延津县| 龙州县| 百色市| 榆中县| 柳河县| 洛浦县| 界首市| 鹤庆县| 贵德县| 黔江区| 肥西县| 常宁市| 二手房| 侯马市| 乐安县| 克山县| 鄂伦春自治旗|