gpt4 book ai didi

ios - NSParagraphStyle 的 paragraphSpacingBefore 不起作用

转载 作者:行者123 更新时间:2023-11-28 17:50:59 25 4
gpt4 key购买 nike

NSParagraphStyle 的 paragraphSpacingBefore 属性似乎没有做任何事情。我很确定它在以前的项目中有效,但我没有发现我的旧代码与我现在正在做的有什么不同。这是我的示例代码:

textView.contentInset = UIEdgeInsetsZero;

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentJustified;
paragraphStyle.firstLineHeadIndent = 22;
paragraphStyle.paragraphSpacingBefore = 120;

NSMutableDictionary *attributes = [NSMutableDictionary new];
[attributes setObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
[attributes setObject:[UIColor clearColor] forKey:NSBackgroundColorAttributeName];
[attributes setObject:[UIFont fontWithName:@"Helvetica" size:19] forKey:NSFontAttributeName];
[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];

textView.attributedText = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda." attributes:attributes];

如有任何建议,我们将不胜感激。

谢谢。

最佳答案

您是否已将 Interface Builder 中的 UITextView 绑定(bind)到变量 textView?

使用Objective-C Literals .

代码已更新

- (void)viewDidLoad {
[super viewDidLoad];
self.textView.backgroundColor = [UIColor grayColor];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentJustified;
paragraphStyle.firstLineHeadIndent = 22;
paragraphStyle.paragraphSpacingBefore = 120;

NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor blackColor],
NSBackgroundColorAttributeName: [UIColor clearColor],
NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:13],
NSParagraphStyleAttributeName: paragraphStyle
};

self.textView.attributedText = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda." attributes:attributes];

}

结果:

enter image description here

关于ios - NSParagraphStyle 的 paragraphSpacingBefore 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36868553/

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