Skip to content

Commit f87bb08

Browse files
committed
补充ASAttributedString.Attribute.ParagraphStyle
1 parent dacc8fb commit f87bb08

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

Demo-Watch/Demo-Watch.xcodeproj/xcshareddata/xcschemes/Demo-Watch WatchKit App.xcscheme

+6-19
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,33 @@
5454
debugDocumentVersioning = "YES"
5555
debugServiceExtension = "internal"
5656
allowLocationSimulation = "YES">
57-
<RemoteRunnable
58-
runnableDebuggingMode = "2"
59-
BundleIdentifier = "com.apple.Carousel"
60-
RemotePath = "/Demo-Watch WatchKit App">
57+
<BuildableProductRunnable
58+
runnableDebuggingMode = "0">
6159
<BuildableReference
6260
BuildableIdentifier = "primary"
6361
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
6462
BuildableName = "Demo-Watch WatchKit App.app"
6563
BlueprintName = "Demo-Watch WatchKit App"
6664
ReferencedContainer = "container:Demo-Watch.xcodeproj">
6765
</BuildableReference>
68-
</RemoteRunnable>
66+
</BuildableProductRunnable>
6967
</LaunchAction>
7068
<ProfileAction
7169
buildConfiguration = "Release"
7270
shouldUseLaunchSchemeArgsEnv = "YES"
7371
savedToolIdentifier = ""
7472
useCustomWorkingDirectory = "NO"
7573
debugDocumentVersioning = "YES">
76-
<RemoteRunnable
77-
runnableDebuggingMode = "2"
78-
BundleIdentifier = "com.apple.Carousel"
79-
RemotePath = "/Demo-Watch WatchKit App">
74+
<BuildableProductRunnable
75+
runnableDebuggingMode = "0">
8076
<BuildableReference
8177
BuildableIdentifier = "primary"
8278
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
8379
BuildableName = "Demo-Watch WatchKit App.app"
8480
BlueprintName = "Demo-Watch WatchKit App"
8581
ReferencedContainer = "container:Demo-Watch.xcodeproj">
8682
</BuildableReference>
87-
</RemoteRunnable>
88-
<MacroExpansion>
89-
<BuildableReference
90-
BuildableIdentifier = "primary"
91-
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
92-
BuildableName = "Demo-Watch WatchKit App.app"
93-
BlueprintName = "Demo-Watch WatchKit App"
94-
ReferencedContainer = "container:Demo-Watch.xcodeproj">
95-
</BuildableReference>
96-
</MacroExpansion>
83+
</BuildableProductRunnable>
9784
</ProfileAction>
9885
<AnalyzeAction
9986
buildConfiguration = "Debug">

Sources/ParagraphStyle.swift

+16
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ extension ASAttributedString.Attribute {
5252
case lineHeightMultiple // CGFloat
5353
case paragraphSpacingBefore // CGFloat
5454
case hyphenationFactor // Float
55+
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *)
56+
case usesDefaultHyphenation // Bool
5557
case tabStops // [NSTextTab]
5658
case defaultTabInterval // CGFloat
5759
case allowsDefaultTighteningForTruncation // Bool
60+
case lineBreakStrategy // NSParagraphStyle.LineBreakStrategy
5861
}
5962

6063
fileprivate let style: [Key: Any]
@@ -82,9 +85,13 @@ extension ASAttributedString.Attribute {
8285
fetch(.lineHeightMultiple) { paragraph.lineHeightMultiple = $0 }
8386
fetch(.paragraphSpacingBefore) { paragraph.paragraphSpacingBefore = $0 }
8487
fetch(.hyphenationFactor) { paragraph.hyphenationFactor = $0 }
88+
if #available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *) {
89+
fetch(.usesDefaultHyphenation) { paragraph.usesDefaultHyphenation = $0 }
90+
}
8591
fetch(.tabStops) { paragraph.tabStops = $0 }
8692
fetch(.defaultTabInterval) { paragraph.defaultTabInterval = $0 }
8793
fetch(.allowsDefaultTighteningForTruncation) { paragraph.allowsDefaultTighteningForTruncation = $0 }
94+
fetch(.lineBreakStrategy) { paragraph.lineBreakStrategy = $0 }
8895
return paragraph
8996
}
9097
}
@@ -144,6 +151,11 @@ extension ASAttributedString.Attribute.ParagraphStyle {
144151
return .init(style: [.hyphenationFactor: value])
145152
}
146153

154+
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *)
155+
public static func usesDefaultHyphenation(_ value: Bool) -> Self {
156+
return .init(style: [.usesDefaultHyphenation: value])
157+
}
158+
147159
public static func tabStops(_ value: [NSTextTab]) -> Self {
148160
return .init(style: [.tabStops: value])
149161
}
@@ -155,6 +167,10 @@ extension ASAttributedString.Attribute.ParagraphStyle {
155167
public static func allowsDefaultTighteningForTruncation(_ value: Bool) -> Self {
156168
return .init(style: [.allowsDefaultTighteningForTruncation: value])
157169
}
170+
171+
public static func lineBreakStrategy(_ value: NSParagraphStyle.LineBreakStrategy) -> Self {
172+
return .init(style: [.lineBreakStrategy: value])
173+
}
158174
}
159175

160176
extension ASAttributedString.Attribute.ParagraphStyle {

0 commit comments

Comments
 (0)