重写UITableViewCell 子类的layoutSubviews 方法
使用Objective-C
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *subview in self.contentView.superview.subviews) {
if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
subview.hidden = NO;
CGRect frame = subview.frame;
frame.origin.x += self.separatorInset.left;
frame.size.width -= self.separatorInset.right;
subview.frame =frame;
}
}
}
使用Swift
override func layoutSubviews() {
super.layoutSubviews()
for item in self.contentView.superview!.subviews {
var subview = item as! UIView
if NSStringFromClass(subview.classForCoder).hasSuffix("SeparatorView") {
subview.hidden = false
var frame = subview.frame
frame.origin.x += self.separatorInset.left
frame.size.width -= self.separatorInset.right
subview.frame = frame
}
}
}
|