我尝试创建一个带有左右边距/插入的UITableViewCell。以前我使用以下Objective-C代码实现过:
- (void)setFrame:(CGRect)frame {
frame.origin.x += 25;
frame.size.width -= 2 * 25;
[super setFrame:frame];
}
这段代码不能直接转换为Swift,因为现在我必须重写公共frame变量,但将此代码放置在该变量的setter中没有任何效果。如何使用此方法或类似方法使边距显示出来?
这是我尝试的Swift代码:
private var otherFrame: CGRect = CGRectZero
override public var frame: CGRect {
get {
return otherFrame
}
set {
otherFrame = frame
otherFrame.origin.x += 25
otherFrame.size.width -= 2 * 25
}
}