Coder_DJ 自定义tableViewCell的侧滑删除按钮
来源:互联网 发布:inputselect.js 编辑:程序博客网 时间:2024/05/16 09:40
转自:http://www.cnblogs.com/Coder-DJ/p/5645392.html
-(void)layoutSubviews
{
[super layoutSubviews];
for (UIView *subView in self.subviews)
{
if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")])
{
UIView *confirmView=(UIView *)[subView.subviews firstObject];
//改背景颜色
confirmView.backgroundColor=[UIColor colorWithWhite:0.898 alpha:1.000];
for(UIView *sub in confirmView.subviews)
{
//修改字的大小、颜色,这个方法可以修改文字样式
/*
if ([sub isKindOfClass:NSClassFromString(@"UIButtonLabel")]) {
UILabel *deleteLabel=(UILabel *)sub;
deleteLabel.backgroundColor = [UIColor redColor];
//改删除按钮的字体大小
deleteLabel.font=[UIFont boldSystemFontOfSize:20];
//改删除按钮的文字
deleteLabel.text=@"嘿嘿";
}
*/
//添加图片
if ([sub isKindOfClass:NSClassFromString(@"UIView")]) {
UIView *deleteView = sub;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"iconfont-zhuchang"];
imageView.frame = CGRectMake(CGRectGetMaxX(sub.frame) - 58, -5, 30, 30);
[deleteView addSubview:imageView];
}
}
break;
}
}
}
这样你就成功的将那个红色背景颜色的delete按钮修改成了一张自定义的图片了。
不过细心的小伙伴一定会发现每次当你点击按钮的时候按钮都会短暂的出现白色的delete文字,别怕,咱们再重写一个方法就好:
#pragma mark 更改删除按钮文字(使文字为空)
-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath {
return @" ";
}
这样就解决了。
有时候也会有侧滑显示两个选项的要求,这个也很简单,在- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath;方法中添加UITableViewRowAction就行,具体的大家自己摸索一下就出来了。
- Coder_DJ 自定义tableViewCell的侧滑删除按钮
- tableViewCell删除按钮自定义
- iOS tableviewcell左划自定义(带图片)删除按钮,点击任意地方取消删除的巧妙实现方法
- tableviewcell 侧滑删除 点击返回按钮 程序崩溃 [ tableView:canEditRowAtIndexPath:]:message sent to deallocated insta
- 自定义TableViewCell上的按钮-找到cell行数
- iOS自定义tableViewCell中的按钮无法点击的解决方法
- tableViewCell左滑出现删除或其它按钮
- 玩转tableViewCell 侧滑按钮UITableViewCellDeleteConfirmationView
- iOS开发 自定义tableviewCell、自动变高、动态布局、删除按钮替换图片和文字
- tableViewcell 的右移多选删除
- 自定义TableViewCell的使用方法
- TableViewCell组件的自定义
- 自定义TableviewCell的UIMenuController
- tableviewcell添加多个按钮删除事件
- [自定义TableViewCell的删除视图 + iOS11下自定义删除失效适配]
- 删除tableviewcell遇到的问题
- 修改UITableViewCell左滑删除按钮的样式和自定义
- 自定义一个tableViewCell的方法
- c++重叠I/0
- IE 盒模型和W3C盒模型
- C++ STL : std::list
- 001——Binder 机制详解—Binder IPC 程序结构
- R语言决策树概论
- Coder_DJ 自定义tableViewCell的侧滑删除按钮
- C++中的可调用对象
- 极其简单的一个JSP小功能+空指针异常Bug解析(内容更新)
- TextView设置个别字体样式
- 线程基础(2)
- vc程序可以运行但没结果
- shape【Android】
- 小游戏键盘操作
- intellij 出现“Usage of API documented as @since 1.6+”的解决办法