From f87bb08252dd55fcdbbabe956e6cf9c64263630c Mon Sep 17 00:00:00 2001 From: LEE <18611401994@163.com> Date: Wed, 27 Apr 2022 18:02:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85ASAttributedString.Attribute.?= =?UTF-8?q?ParagraphStyle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Demo-Watch WatchKit App.xcscheme | 25 +++++-------------- Sources/ParagraphStyle.swift | 16 ++++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Demo-Watch/Demo-Watch.xcodeproj/xcshareddata/xcschemes/Demo-Watch WatchKit App.xcscheme b/Demo-Watch/Demo-Watch.xcodeproj/xcshareddata/xcschemes/Demo-Watch WatchKit App.xcscheme index 93fc253..b566826 100644 --- a/Demo-Watch/Demo-Watch.xcodeproj/xcshareddata/xcschemes/Demo-Watch WatchKit App.xcscheme +++ b/Demo-Watch/Demo-Watch.xcodeproj/xcshareddata/xcschemes/Demo-Watch WatchKit App.xcscheme @@ -54,10 +54,8 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - + - + - + - - - - - + diff --git a/Sources/ParagraphStyle.swift b/Sources/ParagraphStyle.swift index 0c2e621..83dea06 100644 --- a/Sources/ParagraphStyle.swift +++ b/Sources/ParagraphStyle.swift @@ -52,9 +52,12 @@ extension ASAttributedString.Attribute { case lineHeightMultiple // CGFloat case paragraphSpacingBefore // CGFloat case hyphenationFactor // Float + @available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *) + case usesDefaultHyphenation // Bool case tabStops // [NSTextTab] case defaultTabInterval // CGFloat case allowsDefaultTighteningForTruncation // Bool + case lineBreakStrategy // NSParagraphStyle.LineBreakStrategy } fileprivate let style: [Key: Any] @@ -82,9 +85,13 @@ extension ASAttributedString.Attribute { fetch(.lineHeightMultiple) { paragraph.lineHeightMultiple = $0 } fetch(.paragraphSpacingBefore) { paragraph.paragraphSpacingBefore = $0 } fetch(.hyphenationFactor) { paragraph.hyphenationFactor = $0 } + if #available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *) { + fetch(.usesDefaultHyphenation) { paragraph.usesDefaultHyphenation = $0 } + } fetch(.tabStops) { paragraph.tabStops = $0 } fetch(.defaultTabInterval) { paragraph.defaultTabInterval = $0 } fetch(.allowsDefaultTighteningForTruncation) { paragraph.allowsDefaultTighteningForTruncation = $0 } + fetch(.lineBreakStrategy) { paragraph.lineBreakStrategy = $0 } return paragraph } } @@ -144,6 +151,11 @@ extension ASAttributedString.Attribute.ParagraphStyle { return .init(style: [.hyphenationFactor: value]) } + @available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *) + public static func usesDefaultHyphenation(_ value: Bool) -> Self { + return .init(style: [.usesDefaultHyphenation: value]) + } + public static func tabStops(_ value: [NSTextTab]) -> Self { return .init(style: [.tabStops: value]) } @@ -155,6 +167,10 @@ extension ASAttributedString.Attribute.ParagraphStyle { public static func allowsDefaultTighteningForTruncation(_ value: Bool) -> Self { return .init(style: [.allowsDefaultTighteningForTruncation: value]) } + + public static func lineBreakStrategy(_ value: NSParagraphStyle.LineBreakStrategy) -> Self { + return .init(style: [.lineBreakStrategy: value]) + } } extension ASAttributedString.Attribute.ParagraphStyle {