如何在 UITextView 中自动换行?

Pan*_*ngu 2 xcode objective-c uiscrollview uitextview ios

我有一个包含在 UIScrollView 中的 UITextView。UITextView 是根据 UISegmentedControl 动态加载的,但我不知道如何自动换行,以便单词移动到下一行。

在此输入图像描述

.米:

@interface Tester ()
{
    UITextView *sponsor;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    sponsorInfo = [ [UITextView alloc] initWithFrame:self.sponsorsScrollView.frame];

    [sponsor setEditable:NO];
}

- (IBAction)control:(UISegmentedControl *)sender
{
    if (self.sponsorSegmentedControl.selectedSegmentIndex == 0)
    {
        [self changeGenericAbout:self.cellIndex];
    }
    else
    {
        //
    }
}

- (void)changeGenericAbout:(int)index
{
    if (index == 0)
    {
        sponsorInfo.text = @"[text in screen shot]";


        [sponsor sizeToFit];
        [self.sponsorsScrollView addSubview:sponsor];
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在 iOS 7+ 中实现自动换行?

Yas*_*ser 5

首先,我认为你的文本视图看起来有点奇怪。右侧不应该也有一个边距吗?现在看起来文本视图继续向右。框架是否正确或者您对 textContainerInset 做了什么?

无论如何,要回答有关更改换行符的问题:textview 的 textContainer 属性有一个 lineBreakMode,可以将其设置为 NSLineBreakByWordWrapping。我认为这应该解决它