//버튼을 커스텀으로 작성
UIButton *checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
//위치 및 크기 조절
checkbox.frame = CGRectMake(100, 100, 100, 100);
//바탕색상조절
checkbox.backgroundColor = [UIColor blueColor];
//노말상태에서 타이틀지정
[checkbox setTitle:@"OFF" forState:UIControlStateNormal];
//선택된상태에서 타이틀지정
[checkbox setTitle:@"ON" forState:UIControlStateSelected];
//클릭시 이벤트 지정
[checkbox addTarget:self action:@selector(onCheckBox:) forControlEvents:UIControlEventTouchUpInside];
이벤트부분
-(void)onCheckBox:(id)sender{
//이벤트 발생버튼 지정
UIButton *button = sender;
//선택값을 반전 시켜줌
button.selected=!button.selected;
}
출처 : http://cafe.naver.com/mcbugi.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=108711&
'프로그램 > iPhone' 카테고리의 다른 글
Programming Apple Push Notification Services (0) | 2011.02.21 |
---|---|
Implement Facebook Connect on the iPhone in 5 minutes (0) | 2011.02.16 |
Xcode의 프로젝트 구조화 해서 템플릿으로 만들기 (0) | 2011.02.14 |
UITableView에서 이미지 동적으로 불러오기 (0) | 2011.02.11 |
UIImageView에 원격이미지 비동기 로드 및 캐쉬 기능 넣기 (0) | 2011.02.11 |