[英]UITextView character wrap but not word wrap
I have a UITextView that I would like to disable word wrap on but keep character wrapping enabled. 我有一个UITextView,我想禁用自动换行,但保持启用字符换行。
Basically I would like to have a long string 200+ characters that still wraps in the textview but prevents word recognition and/or word wrap. 基本上,我想使用200个以上的长字符串,这些字符串仍会包裹在textview中,但会阻止单词识别和/或自动换行。 Is this possible and if so can someone point me in the right direction? 这有可能吗?如果可以,有人可以指出我正确的方向吗?
Thanks! 谢谢!
This is not possible with a stock UITextView
, because there is no lineBreakMode
property in its public API. 对于普通的UITextView
,这是不可能的,因为在其公共API中没有lineBreakMode
属性。 If you don't need the text to be editable, you could look into other solutions such as a UILabel
or Core Text. 如果您不需要文本是可编辑的,则可以考虑使用其他解决方案,例如UILabel
或Core Text。 Getting this behavior in an editable control is possible, but will probably be a pretty hard slog. 在可编辑控件中实现此行为是可能的,但可能很难做到。
you can try 你可以试试
NSMutableAttributedString *att=[[NSMutableAttributedString alloc]initWithString:str];
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[att addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.