如何确定 UITextfield 中文本的长度
我有一个 UITextField,我想从中确定输入文本的宽度。
bounds 属性仅具有文本字段的大小,但不具有文本的大小
I have a UITextField from which I'd like to determine the width of the entered text.
The bounds property has just the size of the Textfield but not of the text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
现在,
sizeWithFont:
在 iOS 7.0 中已弃用,请使用https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/#//apple_ref/occ/instm/NSString/sizeWithAttributes:
Now that
sizeWithFont:
is deprecated in iOS 7.0 usehttps://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/#//apple_ref/occ/instm/NSString/sizeWithAttributes:
如果您正在寻找字符数,那就是这个
如果您正在寻找像素宽度,请尝试这个
If you are looking for character count it is this
If you are looking for pixel width try this
在斯威夫特 3.0 中:
In Swift 3.0:
此处的文档: http://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/occ/instm/NSString/sizeWithFont:
Documentation here: http://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/occ/instm/NSString/sizeWithFont:
这个 UILabel 中文本的像素宽度有帮助吗?
Does this Pixel Width of the text in a UILabel help ?
textField 是界面生成器中的委托,比......
[textField.text length]
textField is delegate which is attac in interface builder than......
[textField.text length]