iphone – UITextView – 水平滚动?
如何创建水平滚动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,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’ 解决方法
我还没有做过这样的事情,但我会尝试以下步骤来完成这个:
>创建UIScrollview * yourScrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0,50)]; // 希望这会给你一个良好的开端! 编辑:本准则将有效: 请注意我使用的是UILabel而不是UITextView. UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectMake(0,40)]; 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."; titleView.font = [UIFont systemFontOfSize:18]; titleView.backgroundColor = [UIColor clearColor]; titleView.numberOfLines = 1; UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,50)]; CGFloat textLength = [titleView.text sizeWithFont:titleView.font constrainedToSize:CGSizeMake(9999,50) lineBreakMode:NSLineBreakByWordWrapping].width; myScrollView.contentSize = CGSizeMake(textLength + 20,50); //or some value you like,you may have to try this out a few times titleView.frame = CGRectMake(titleView.frame.origin.x,titleView.frame.size.height); [myScrollView addSubview: titleView]; [self.view addSubview:myScrollView]; [titleView release]; [myScrollView release]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |