gpt4 book ai didi

ios - iOS 7 属性字符串绘制方法中 NSLineBreakMode 的等价物是什么?

转载 作者:IT王子 更新时间:2023-10-29 07:51:15 26 4
gpt4 key购买 nike

有一个方法

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment;

我现在必须为 iOS 7 替换它。我得到了

NSDictionary *attributes = @{NSFontAttributeName: font};
[self drawInRect:rect withAttributes:attributes];

但是如何指定自动换行的换行方式呢?我搜索了属性字符串绘图符号的文档,但没有提到换行模式。这是否总是自动换行?

最佳答案

您需要创建段落样式。

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setLineBreakMode:NSLineBreakByWordWrapping];

NSDictionary *attributes = @{NSFontAttributeName: font, NSParagraphStyleAttributeName: style};
[self drawInRect:rect withAttributes:attributes];

更多信息在这里: https://developer.apple.com/documentation/uikit/nsparagraphstyle?language=objc

关于ios - iOS 7 属性字符串绘制方法中 NSLineBreakMode 的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19197709/

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