IOS开发自定义CheckBox控件
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];
IOS开发自定义CheckBox控件的更多相关文章
- IOS开发--自定义segment控件,方便自定义样式
系统的segment控件太封闭,想换个颜色加个背景太难了,忍不住自己写一个,以备不时之需 这个控件给出了很多自定义属性的设置,用起来还是比较方便的,需要注意的 itemWidth如果不设置,则会按照控 ...
- 继续聊WPF——自定义CheckBox控件外观
上一篇文章中谈到了BulletDecorator控件,就是为自定义CheckBox控件的模板做准备,因为CheckBox需要比较严格的布局,正好,BulletDecorator控件就合适了,该控件的布 ...
- iOS 开发 ZFUI framework控件,使布局更简单
来自:http://www.jianshu.com/p/bcf86b170d9c 前言 为什么会写这个?因为在iOS开发中,界面的布局一直没有Android布局有那么多的方法和优势,我个人开发都是纯代 ...
- IOS开发中设置控件内容对齐方式时容易混淆的几个属性
IOS开发中四个容易混淆的属性: 1. textAligment : 文字的水平方向的对齐方式 1> 取值 NSTextAlignmentLeft = 0, // 左对齐 NST ...
- ios开发中button控件的属性及常见问题
最为最基本的控件,我们必须对button的每个常用属性都熟练应用: 1,使用之前,必须对按钮进行定义,为乐规范,在@interface ViewController (){}中进行定义,先定义后使用. ...
- iOS开发基础-UITableView控件简单介绍
UITableView 继承自 UIScrollView ,用于实现表格数据展示,支持垂直滚动. UITableView 需要一个数据源来显示数据,并向数据源查询一共有多少行数据以及每一行显示什么 ...
- iOS开发无第三方控件的援助达到的效果侧边栏
最近的研究iOS程序侧边栏.渐渐的发现iOS该方案还开始采取风侧边栏格该,QQ,今日头条,Path(Path运营商最早的侧边栏app该,效果说成是Path效果),所以就研究了下. 然后发现Git Hu ...
- iOS开发中UIDatePicker控件的使用方法简介
iOS上的选择时间日期的控件是这样的,左边是时间和日期混合,右边是单纯的日期模式. 您可以选择自己需要的模式,Time, Date,Date and Time , Count Down Timer四 ...
- IOS开发之按钮控件Button详解
reference:http://mxcvns.lofter.com/post/1d23b1a3_685d59d 首先是继承问题,UIButton继承于UIControl,而UIControl继承于U ...
随机推荐
- Windows 和Linux 误删除后的恢复
ext文件系统上删除文件,可以恢复:extundelete; windows 恢复删除文件: final data v2.0汉化版 和 easyrecovery
- WDCP各种停止重启命令
service wdapache start|stop|restart wdcp后台 启动|停止|重起service nginxd start|stop|restart nginx ...
- LINUX gcc安装rpm包顺序
rpm -ivh cpp-4.1.2-42.el5.i386.rpm rpm -ihv kernel-headers-2.6.18-92.el5.i386.rpm rpm -ivh glibc-hea ...
- tp总结
不知不觉学tp也快一个月了,虽然还处于一个仅仅只会使用的阶段,但毕竟算是我详细接触的第一个脚本框架,tp还是让我收获了许多. 废话不多说,先列出几个对于我这种新手来说tp新奇而实用的地方. 1.连贯操 ...
- Django 中form的用法
form的主要作用:1.在html中生成表单框架,2.验证数据(实话实说,很简洁,但不实用,灵活性差) from django.db import models # Create your model ...
- MongoDB权威指南--笔记
mongodb并不具备一些在关系型数据库中很普遍的功能,如连接和复杂的多行事务. 集合-->文档-->id id在文档所属的集合中是唯一的. db.help()查看数据库级别的帮助,db. ...
- 常用开放api【长期更新】
获取时间: 苏宁:http://quan.suning.com/getSysTime.do 淘宝:http://api.m.taobao.com/rest/api3.do?api=mtop.commo ...
- HDU - 4777 离线树状数组
离线树状数组搞一搞. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #de ...
- TestDirector自定义管理:用户配置
一.进入Customize 1.打开TD,点击TestDirector,进入登录界面,在TD登录页面右上角点击“CUSTOMIZE(自定义)”. 2.选择要登录的域和项目,输入用户帐号和密码,点击确定 ...
- poj1606 Jugs(BFS)
题目链接 http://poj.org/problem?id=1606 题意 有两个容量分别为ca,cb的杯子,可以向杯子里倒水,将杯子里的水倒空,将一个杯子里的水倒到另一个杯子里,求怎样倒才能使其中 ...