IOS开发之TableView替换默认的checkmark为自定义图像
2013-08-02 16:12
525 查看
直接上代码:
On
checkButtonTapped:event: Method:
accessoryButtonTappedForRowWithIndexPath: Method
On
cellForRowAtIndexPath:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height); button.frame = frame; [button setBackgroundImage:image forState:UIControlStateNormal]; [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; button.backgroundColor = [UIColor clearColor]; cell.accessoryView = button;
checkButtonTapped:event: Method:
- (void)checkButtonTapped:(id)sender event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition]; if (indexPath != nil) { [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath]; } }
accessoryButtonTappedForRowWithIndexPath: Method
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row]; BOOL checked = [[item objectForKey:@"checked"] boolValue]; [item setObject:[NSNumber numberWithBool:!checked] forKey:@"checked"]; UITableViewCell *cell = [item objectForKey:@"cell"]; UIButton *button = (UIButton *)cell.accessoryView; UIImage *newImage = (checked) ? [UIImage imageNamed:@"unchecked.png"] : [UIImage imageNamed:@"checked.png"]; [button setBackgroundImage:newImage forState:UIControlStateNormal]; }
相关文章推荐
- IOS开发之TableView替换默认的checkmark为自定义图像
- iOS开发技巧-tableView去掉多余的空行分割线,自定义Cell分割线
- IOS开发系列--TableView、多个TableViewCell、自定义Cell、Cell上画画(故事板+代码方式),ios7tableview索引
- iOS开发 自定义tableView样式(使用代码/使用Interface Builder)、分组显示、给TableView增加索引、给TableView增加SearchBariOS开发 自定义tab
- ((ios开发学习笔记 十一))自定义TableViewCell 的方式实现自定义TableView(带源码)
- iOS开发中如何自定义tableView的分割线
- iOS开发 自定义tableView样式(使用代码/使用Interface Builder)、分组显示、给TableView增加索引、给TableView增加SearchBar
- iOS开发中自定义tableView中某个cell的高度
- iOS开发中tableview中cell图片大小自定义方法
- 芒果iOS开发之iOS9TableView分割线默认不显示,只有滑动的时候才显示
- iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除
- iOS开发技巧-tableView去掉多余的空行分割线,自定义Cell分割线
- IOS开发之TableView、多个TableViewCell、自定义Cell、Cell上画画(故事板+代码方式)
- iOS开发之高级转场动画,tableview到collectionView自定义转场动画+手势驱动
- iOS开发中tableview中cell图片自定义方法。
- ios开发技巧之tableView去掉多余的空行分割线 自定义cell分割线
- iOS开发系列 ---- UI (自定义TableView)
- 【iOS开发TableView】TabelView自定义cell
- iOS开发笔记--TableView的详细使用
- iOS开发之高级视图—— UITableView(四)自定义Cell