开发者

Creating paragraphs in UITextview

开发者 https://www.devze.com 2022-12-27 04:23 出处:网络
Is it possible to split the text into par开发者_StackOverflowagraph in a UITextView?It\'s possible.

Is it possible to split the text into par开发者_StackOverflowagraph in a UITextView?


It's possible.

Example:

UITextView *testTextView = [[UITextView alloc] initWithFrame:frame];

[testTextView setText:@"More\nBooks"];

It's displayed like 2 strings:

More

Books

Key for answer is: \n - end of line symbols.


use NSMutableParagraphStyle in attributed string. and check other properties instead of paragraphSpacingBefore;

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle.paragraphSpacingBefore = 33.;

_textView.attributedText = [[NSAttributedString alloc] initWithString:string attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号