【问题标题】:UITextView Resize - Large Text cutted of from landscape to portraitUITextView Resize - 从横向到纵向的大文本
【发布时间】:2014-02-28 17:02:35
【问题描述】:

我有一个关于调整UITextView 大小的问题。我有一个位于UIView 容器内的文本视图。当应用程序启动时,容器只显示工具栏,当用户点击它时,textview 的UIView 被添加为容器的子视图并显示文本。当用户再次点击工具栏时,UITextView 的视图将从其父视图(容器)中移除,依此类推。 每次我需要调整 textview 的大小时,我都会使用以下代码计算它的尺寸并记录值,它们是正确的。

  CGSize size = [stringToUse  sizeWithFont:[self.synthesisTextView font]
                        constrainedToSize:CGSizeMake(synthesisTextViewBounds.size.width, FLT_MAX)
                        lineBreakMode:NSLineBreakByWordWrapping];

    [self.synthesisTextView setScrollEnabled:YES];

    [self.synthesisTextView setContentSize:CGSizeMake(synthesisTextViewBounds.size.width,
                                                      size.height + 50)];

    [self.synthesisTextView setFrame:CGRectMake(synthesisTextViewFrame.origin.x,
                                                synthesisTextViewFrame.origin.y,
                                                synthesisTextViewBounds.size.width,
                                                size.height + 50)];

    [self.synthesisLabel setFrame:CGRectMake(self.synthesisLabel.frame.origin.x,
                                             self.synthesisLabel.frame.origin.y,
                                             self.synthesisLabel.frame.size.width,
                                             size.height + 50)];

即使UITextView 具有正确的尺寸,文本也会被截断。

以下是我执行的步骤:

  1. 我在 lanscape 中打开应用程序,我可以看到工具栏。
  2. 我点击工具栏,计算 textview 大小并将其添加为 容器的子视图,然后调整它的大小。 (这里的维度是 对)。
  3. 我旋转设备,调整文本视图大小(尺寸为 对) - 风景!!
  4. 我再次点击工具栏以关闭容器。我删除 UITextView 来自容器,然后调整它的大小。
  5. 我再次点击工具栏。 textview 被添加为 容器并具有正确的尺寸 (LANDSCAPE)。
  6. 我在 PORTRAIT 中旋转设备。文本视图维度是 计算正确,但文本结果被截断。

我该如何解决我的情况?

非常感谢!!

咻!!

【问题讨论】:

    标签: ios objective-c uitextview


    【解决方案1】:
    //textView Height as per content
    
    CGRect frame = viewNote.frame;
    NSLog(@"Text Size height : %f",frame.size.height);
    
    CGSize textViewSize;
    if (isIPhone) {
        textViewSize = [viewNote.text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:20]
                                        constrainedToSize:CGSizeMake(309, 10000)
                                            lineBreakMode:UILineBreakModeTailTruncation];
    }else{
        textViewSize = [viewNote.text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:30]
                                        constrainedToSize:CGSizeMake(768, 10000)
                                            lineBreakMode:UILineBreakModeTailTruncation];
    }
    
    frame.size.height = textViewSize.height;
    viewNote.frame = frame;
    

    【讨论】:

    • 感谢 mohitpopat,我已经尝试过您的实现,但不幸的是确实可以像我一样工作。 textview 的宽度总是正确的。只有textview不能正确显示文本并剪切的情况
    猜你喜欢
    • 1970-01-01
    • 2013-11-24
    • 2012-10-12
    • 2017-07-27
    • 1970-01-01
    • 2023-03-05
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多