子类化UITextView(和UICollectionView)的问题是指定的构造函数是"initWithFrame".但在现实生活中,当它从故事板加载时,将调用initWithCoder.
class BorderedTextView: UITextView {
//will be called
init(coder: NSCoder?){
//constant values here is not an option
super.init(frame: CGRectMake(0,0,100,100), textContainer: nil)
}
//will not be called
init(frame: CGRect, textContainer: NSTextContainer!) {
super.init(frame: frame, textContainer: textContainer)
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我无法在init上调用任何UI自定义代码,并为除默认值之外的Swift变量提供任何初始化值.
我想通过从"编码器"中提取帧大小可以暂时解决问题,但我没有找到它的关键.
任何想法比硬编码帧值更好?