ios开发教程自定义checkbox控件

ios开发教程自定义checkbox控件

ID:8789382

大小:81.10 KB

页数:5页

时间:2018-04-07

ios开发教程自定义checkbox控件_第1页
ios开发教程自定义checkbox控件_第2页
ios开发教程自定义checkbox控件_第3页
ios开发教程自定义checkbox控件_第4页
ios开发教程自定义checkbox控件_第5页
资源描述:

《ios开发教程自定义checkbox控件》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、IT在线教育平台———麦子学院:http://www.maiziedu.com首先创建工程文件,CheckBox,然后创建CheckBox类,继承自UIView,同时添加资源文件,选中、取消的图片,添加完成以后目录如下:CheckBox类头文件代码如下:1.#import  2.  3.@protocolCheckBoxDelegate;  4.  5.@interfaceCheckBox:UIView  6.  7.@property(nonatomic,retain)NSString*text;//显示文字  8.@property(nonatomic,a

2、ssign)BOOLchecked;//是否选中  9.  10.@property(nonatomic,retain)iddelegate;//代理  IT在线教育平台———麦子学院:http://www.maiziedu.com1.  2.-(id)initWithText:(NSString*)textframe:(CGRect)frame;//初始化  3.  4.@end  5.  6.@protocolCheckBoxDelegate  7.  8.-(void)onChangeDelegate:(CheckBox*)ch

3、eckboxisCheck:(BOOL)isCheck;  9.  10.@end复制代码CheckBox实现代码如下:1.#import"CheckBox.h"  2.@interfaceCheckBox()  3.  4.@property(nonatomic,retain)UIImage*onImage;  5.@property(nonatomic,retain)UIImage*offImage;  6.  7.@end  8.  9.  10.@implementationCheckBox  11.  12.-(void)dealloc{  13.  [_textrelease]

4、;  14.  [_delegaterelease];  15.  [_onImagerelease];  16.  [_offImagerelease];  17.  [superdealloc];  18.}  IT在线教育平台———麦子学院:http://www.maiziedu.com1.-(id)initWithFrame:(CGRect)frame  2.{  3.  self=[superinitWithFrame:frame];  4.  if(self){  5.      //Initializationcode  6.  }  7.  returnself;  8.}

5、  9.-(id)initWithText:(NSString*)textframe:(CGRect)frame{  10.  self=[superinitWithFrame:frame];  11.  if(self){  12.      _text=text;  13.      self.backgroundColor=[UIColorclearColor];  14.      self.onImage=[UIImageimageNamed:@"chk_on.png"];//选中图片  15.      self.offImage=[UIImageimageNamed:@"ch

6、k_off.png"];//取消图片  16.  }  17.  returnself;  18.}  19.-(void)setChecked:(BOOL)checked{  20.  _checked=checked;  21.  //注册代理事件,通知状态改变  22.  if([self.delegaterespondsToSelector:@selector(onChangeDelegate:isCheck:)]){  23.      [self.delegateonChangeDelegate:selfisCheck:_checked];  24.  }  25.    26

7、.  [selfsetNeedsDisplay];  27.}  28.-(void)drawRect:(CGRect)rect{//将text,image绘制到UIView上面  29.  UIImage*image=self.checked?self.onImage:self.offImage;  30.  [imagedrawAtPoint:CGPointMake(5,8)];  31.  UIFont*font=

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。