您的位置:首页 > 产品设计 > UI/UE

UITableView 编辑模式左边图标的替换

2015-08-23 00:00 766 查看
摘要: 替换UITableVeiw编辑模式左边系统图标

在自定义的cell类中,添加

swift:

override func setSelected(selected: Bool, animated: Bool) {

super.setSelected(selected, animated: animated)

if self.editing {

for (var control) in self.subviews {

if control.isMemberOfClass(NSClassFromString("UITableViewCellEditControl")) {

control = control as! UIControl

if selected {

(control.subviews.last as! UIImageView).image = UIImage(named: "compass")

} else {

control.layer.backgroundColor = self.backgroundColor?.CGColor

}

}

}

}

}

oc:

- (
void
)setSelected:(
BOOL
)selected animated:(
BOOL
)animated


{


 
[
super
setSelected:selected animated:animated];


 
if
(![
self
.viewcontroller isEditing]) {




 
self
.selectionStyle = UITableViewCellSelectionStyleNone;




 
}
else
{




 
self
.selectionStyle = UITableViewCellSelectionStyleBlue;




 
//Bug fix: 第一次点击cell的左侧的复选框无法选中


 
//手动增加edit control的处理


 
for
(UIControl *control in
self
.subviews){




 
if
([control isMemberOfClass:
NSClassFromString
(@
"UITableViewCellEditControl"
)]){


 
[control setSelected:selected];




 
if
(selected) {


 
[control setBackgroundColor:[UIColor colorWithRed:0.91f green:0.94f blue:0.98f alpha:1.00f]];


 
}
else
{


 
[control setBackgroundColor:
self
.backgroundColor];


 
}


 
}


 
}


 
}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: