【问题标题】:size of the NSString to fit on UItextviewNSString 的大小以适合 UItextview
【发布时间】:2012-11-01 12:02:54
【问题描述】:

我想找到要在 UITextview 上显示的 NSString 的大小。它对英语很好。但如果字符串是其他语言,如西班牙语、印地语、日语,则表示它运行缓慢:

CGSize ContentSize=[MainContentString sizeWithFont:TextView.font constraintToSize:CSize lineBreakMode:UILineBreakModeWordWrap];

有没有办法更快?

【问题讨论】:

  • 请显示“工作缓慢”的代码。
  • ContentSize=[[MainContentString substringFromIndex:index] sizeWithFont:TextView.font constrainedToSize:CSize lineBreakMode:UILineBreakModeWordWrap];

标签: objective-c ios nsstring uitextview


【解决方案1】:

实际上有一种非常简单的方法可以将 UITextView 的大小调整为内容的正确高度。可以使用 UITextView contentSize 来完成。

CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

【讨论】:

  • 我不想调整文本视图的大小。我想找出 NSString 的 CGsize。它也工作正常。但它对印地语、泰米尔语等其他语言的运行速度很慢。
【解决方案2】:

查看 UIView 的 autoresizesSubviewscontentMode - 在情节提要中与他们一起玩。

在有和没有你的实现的情况下都试试 - 看看它是否有效。

【讨论】:

    猜你喜欢
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    相关资源
    最近更新 更多