如何创建水平滚动 UITextView?
当我以编程方式设置文本时,它会添加自动换行符,所以我只能垂直滚动......
titleView.text = @"this is a very long text. this is a very long text. this is a very long text. this is a very long text. this is a very long text.";
感谢您的回答。
编辑:到目前为止我试过这个:
UIScrollview *yourScrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0 ,0 , self.view.frame.size.width, 50)];
CGFloat textLength = [titleView.text sizeWithFont:titleView.font constrainedToSize:CGSizeMake(9999, 50) lineBreakMode:NSLineBreakByWordWrapping].width;
yourScrollview.contentSize = CGSizeMake(textLength + 200, 500); //or some value you like, you may have to try this out a few times
titleView.frame = CGRectMake(titleView.frame.origin.x, titleView.frame.origin.y, textLength, titleView.frame.size.height);
[yourScrollview addSubview: titleView];
NSLog(@"%f", textLength);
但我收到:“威胁 1:信号 SIGABRT”