Post

Replies

Boosts

Views

Activity

NSFontPanel: how to preselect foreground color
Hi everybody.This is how I've set up a viewController in order to display the shared FontPanel, thereby letting the user chose a specific font.class GeneralViewController: NSViewController { @objc func changeFont(_ sender: NSFontManager) { let sharedFontManager = NSFontManager.shared . . . // Works just fine } @objc func changeAttributes(_ sender: AnyObject) { let convertedAttributes: [String: Any?] = sender.convertAttributes([:]) guard let color = convertedAttributes[NSAttributedString.Key.foregroundColor.rawValue] as? NSColor else { return } . . . // Works just fine } @IBAction func selectFontAndColorAction(_ sender: NSButton?) { let sharedFontManager = NSFontManager.shared sharedFontManager.target = self triggeredBy = sender?.identifier let selectedFont = NSFont...... let selectedColor = NSColor...... sharedFontManager.setSelectedFont(selectedFont, isMultiple: false) /// FIX: - My try!!! Not Working!!! sharedFontManager.setSelectedAttributes([NSAttributedString.Key.foregroundColor.rawValue: selectedColor], isMultiple: false) /// My Try!!! Not Working sharedFontManager.orderFrontFontPanel(sender) } }So far, I've manged to show the fontPanel and I'm able to select (choose) any font properly, along with its attributes (underline style, underline color, etc.)What I'm not able to implement (googled a lot but to no avail, docs and tutorials are very scarse) is a way to set the initial foreground color displayed in the fontpanel's attributes toolbar. I get always BlackCan anyone shed some light on the matter?Thank youP.S.: My dev target is AppKit, not UIKIT
1
0
655
Mar ’20
Are IBOutlet collections gone from Xcode 11
The syntax used to declare an IBOutlet collection, if I'm not wrong, should beclass myViewController: NSViewController { // MARK: - Outlets @IBOutlet var collection: [NSButton] = [NSButton]() . . .But by no means I can connect such outlet collections to my objects in the storyboard.Apparently, Outlet Collections have disappeared form Xcode 11.As you can see in the picture, the Outlet Collection option has gone.or the other way aroundIs there some new feature I'm missing?Thank you
1
0
1.5k
Mar ’20