Post

Replies

Boosts

Views

Activity

NSLayoutManager.drawGlyphs() can not display MarkDown attributed string
We use NSLayoutManager/NSTextStorage/NSTextContainer to display markdown attributed string on a canvas. MarkDown string was processed properly, but NSLayoutManager just exhibits the plain text. The code is as follows:     var layoutmanager = NSLayoutManager()     var textstorage = NSTextStorage()     var textcontainer = NSTextContainer()   var attrStr = try AttributedString.init(markdown: "**test**", options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace)) var attrString = NSMutableAttributedString(attrStr)  self.textstorage.setAttributedString(attrString!) // draw text layout     let range = self.layoutmanager.glyphRange(for: self.textcontainer)     self.layoutmanager.drawBackground(forGlyphRange: range, at: self.textLocation)     self.layoutmanager.drawGlyphs(forGlyphRange: range, at: self.textLocation) Is it because TextKit 1 does not support markdown string display or I miss something else ? Any help will be appreciated. Thanks!
1
0
1.3k
Sep ’21
How to create different scenes with different views by code?
WWDC2020 videos said SwiftUI on Xcode12 can create and manage different scenes in an App, but we do not find out any API could do that. We try the method  of SwiftUI on Xcode11 to create new Window on Xcode 12 : UIApplication.shared.requestSceneSessionActivation(nil, userActivity: nil, options: nil, errorHandler: nil) }) But it does not work as we expect. The code create a window of the same scene. If we set a different userActivity, SwiftUI have no method to set SceneDelegate.swift. It only has @UIApplicationDelegateAdaptor to set AppDelegate.  So, I Wonder whether there is a convenient way to create a new Scene by new SwiftUI APIs. The following code can only create Scenes with the same content view : @main struct test: App {       let newWindowPublisher = NotificationCenter.default.publisher(for: Notification.Name("anotherScene"))       var body: some Scene {             WindowGroup {                    ContentView()                          .onReceive(newWindowPublish, perform: { info in                             UIApplication.shared.requestSceneSessionActivation(nil, userActivity: nil, options: nil, errorHandler: nil) })             }        } }
1
0
3.3k
Aug ’20