ios本身沒有系統的checkbox元件,但是實際開發中會經常用到,所以專門寫了乙個checkbox控制項,直接上**
效果圖:
uicheckboxbutton.h檔案如下:
#import
#import "common.h"
@inte***ce 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開發 自定義列表
tableview幾乎是ios裡面最常用的布局了,這裡用純 的方式實現了自定義列表cell的介面 自定義cell cardlist created by yxhe on 16 5 17.end customcellview.m cardlist created by yxhe on 16 5 17....
iOS基礎開發 自定義控制項
自定義控制項,設定子控制項的尺寸和位置 當系統提供的控制項滿足不了我們的需求,我們可以自定義乙個控制項,繼承系統自帶的控制項,寫乙個屬於自己的控制項.自定義控制項的好處是可以把封裝控制項內部的細節,不容易被外界隨意修改.如果乙個view內部的子控制項比較多,一般會考慮自定義乙個view,把它內部子控...
iOS開發 自定義併發NSOperation實戰
前一章節已經介紹了如何自定義併發nsoperation,本節將其應用到具體例項,如果自定義併發nsoperation不會,請移步 在zccurrentoperation.h檔案中 如下 zccurrentoperation.h 自定義非併發nsoperation created by mrzhao ...