我有一个包含在 UIScrollView 中的 UITextView。 UITextView 是根据 UISegmentedControl 动态加载的,但我不知道如何自动换行,以便单词移动到下一行。
.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)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];
}
}
如何在 iOS 7+ 中实现自动换行?
最佳答案
首先,我认为你的 TextView 看起来有点奇怪。右侧不应该也有一个边距吗?现在看起来 TextView 继续向右。框架是否正确或者您对 textContainerInset 做了什么操作?
无论如何,回答有关更改换行符的问题:textview 的 textContainer 属性有一个 lineBreakMode,可以将其设置为 NSLineBreakByWordWrapping。我认为应该可以解决这个问题
关于ios - 如何在 UITextView 中自动换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27086740/