【发布时间】:2020-01-22 12:49:34
【问题描述】:
我一直在 Objective-C 中工作,我使用 Swift 的时间很短。我在 Objective- 中有一个 UITextView 类C 我正在研究intrinsicContentSize 方法。
Objective-C
-(CGSize)intrinsicContentSize {
if ([self.text length]) return self.contentSize;
else return CGSizeZero;
}
现在我正在尝试将我的 Objective-C 代码转换为 Swift,但我遇到了这个函数的问题......
override var intrinsicContentSize: CGSize {
if text.lenght() {
return contentSize
} else {
return CGSize.zero
}
}
text.lenght 似乎给了我一个
类型错误的值'(UITextRange)->字符串?没有成员“长度”
【问题讨论】:
-
见stackoverflow.com/questions/24037711/get-the-length-of-a-string Swift 中检索字符串长度的方式不同
-
@ArikSegal 我试图替换 text.length context.count 或 text.character.count 但它一直给我同样的错误..因此我不明白我错在哪里
-
代码中的错字:
lenght→length -
这能回答你的问题吗? Get the length of a String
标签: ios objective-c swift uitextview intrinsic-content-size