UITableViewCell에서 UI를 수정하려는 경우 @angshuk 대답이 완벽합니다. 제 경우처럼 스토리 보드/autolayout을 사용하여 UITableViewCell 내부에 배치 된 UIView에 런타임에 다른 레이어를 추가하려고했습니다. 같은 것을 내부에서 시도했습니다 awakeFromNib()
& layoutSubviews()
도 있습니다. 아무것도 효과가 없습니다.
여기에는 Swift를 사용하는 코드가 있습니다. 그런데 Swift 2.2에서 Xcode 7.3.1을 사용하고 있습니다.
import UIKit
class InviteMainCellClass: UITableViewCell {
@IBOutlet weak var shareCodeLblSuperView: UIView! //Custom view added using IB/Autolayout
override func awakeFromNib() {
super.awakeFromNib()
//shareCodeLblSuperView.addDashedBorderToView(self.shareCodeLblSuperView, viewBorderColor: UIColor.whiteColor(), borderWidth: 1.0) //Not worked
}
override func drawRect(rect: CGRect) {
super.drawRect(rect)
shareCodeLblSuperView.addDashedBorderToView(self.shareCodeLblSuperView, viewBorderColor: UIColor.whiteColor(), borderWidth: 1.0) //Worked
}
override func layoutSubviews() {
super.layoutSubviews()
//shareCodeLblSuperView.addDashedBorderToView(self.shareCodeLblSuperView, viewBorderColor: UIColor.whiteColor(), borderWidth: 1.0)//Not worked
}
희망이 도움이되었습니다. 감사.
applyLayoutAttributes는 collectionCells에서만 작동하는 것으로 보입니다. 내 UITableViewCell 들어 당신 drawRect 사용 : 답변 - 감사합니다! – amergin
이것은 나를 위해 일했지만 drawRect를 무시하면 대개 성능이 저하됩니까? –