OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 UITextView 中自动换行? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:57
标题: ios - 如何在 UITextView 中自动换行?

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

enter image description here

.m:

@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)controlUISegmentedControl *)sender
{
    if (self.sponsorSegmentedControl.selectedSegmentIndex == 0)
    {
        [self changeGenericAbout:self.cellIndex];
    }
    else
    {
        //
    }
}

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


        [sponsor sizeToFit];
        [self.sponsorsScrollView addSubview:sponsor];
    }
}

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



Best Answer-推荐答案


首先,我认为您的 textview 看起来有点奇怪。右边不应该也有边距吗?现在它看起来像 textview 继续向右。框架是正确的还是你对 textContainerInset 做了什么?

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

关于ios - 如何在 UITextView 中自动换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27086740/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4