收藏 分销(赏)

ios开发自定义checkbox控件.doc

上传人:人****来 文档编号:9778005 上传时间:2025-04-07 格式:DOC 页数:2 大小:19KB
下载 相关 举报
ios开发自定义checkbox控件.doc_第1页
第1页 / 共2页
ios开发自定义checkbox控件.doc_第2页
第2页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
  ios本身没有系统的checkbox组件,但是实际开发中会经常用到,所以专门写了一个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 getcolorbytag:@alertlabelcolor];   [self.view addsubview:checkboxbutton];   [checkboxbutton release];   更多信息请查看IT技术专栏   
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服