gpt4 book ai didi

ios - UITextView 文本在文本中间的每个单词之间留出小间隙

转载 作者:行者123 更新时间:2023-11-29 00:31:45 25 4
gpt4 key购买 nike

团队,

我让 UITextView 添加了文本内容,使用字体系列 avinar roma,我注意到每个单词之间的间隙很小,不一致。如何避免每个单词在 textview 文本中出现小间隙。

enter image description here

    descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, titlelabel.frame.origin.y + titlelabel.frame.size.height + 5, view.frame.size.width - 40, view.frame.size.height - 150)];
descriptionTextView.backgroundColor = [UIColor clearColor];
descriptionTextView.textColor = MH_PANTONE_444;
descriptionTextView.textAlignment = NSTextAlignmentCenter;
descriptionTextView.font = [UIFont fontWithName:MH_FONT_AVENIRROMAN size:MH_SCREEN_HEIGHT/48];
descriptionTextView.text = [descriptionArray objectAtIndex:index];
descriptionTextView.editable = NO;
descriptionTextView.scrollEnabled = NO;
descriptionTextView.selectable = YES;
descriptionTextView.dataDetectorTypes = UIDataDetectorTypeAll;

请附上图片大学医学中心,与剩余文本不相同。

最佳答案

设置hyphenationFactor应该可以解决您的问题。但你必须使用 NSAttributedString 而不是纯文本:

UIFont *font = [UIFont fontWithName: MH_FONT_AVENIRROMAN size: MH_SCREEN_HEIGHT/48];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.hyphenationFactor = 1.0;

NSDictionary *attributes = @{ NSFontAttributeName:font,
NSForegroundColorAttributeName: MH_PANTONE_444;
NSParagraphStyleAttributeName: paragraphStyle };

NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString: [descriptionArray objectAtIndex:index]
attributes: attributes];

descriptionTextView.attributedText = attributedText;

https://developer.apple.com/reference/uikit/nsmutableparagraphstyle/1535553-hyphenationfactor

您可能需要调整hyphenationFactor,直到获得所需的结果。 (0.0-1.0)

关于ios - UITextView 文本在文本中间的每个单词之间留出小间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41585590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com