cocoa

How to install custom font in mac programmatically in macOS

隐身守侯 提交于 2020-03-24 21:23:11
问题 I am having a mac app in which I have custom font which is not there in my custom font book of application folder in my mac. So, when an app launches, I checked it that if a font is installed in mac or not with the below code. NSArray *fonts = [[NSFontManager sharedFontManager] availableFontFamilies]; if ([fonts containsObject:@"Square721 BT"]) { NSLog(@"Fonts Available"); } else { NSLog(@"No fonts"); } Now, if the font is not already installed, how can I install it programmatically? 回答1: Add

How to install custom font in mac programmatically in macOS

六眼飞鱼酱① 提交于 2020-03-24 21:23:03
问题 I am having a mac app in which I have custom font which is not there in my custom font book of application folder in my mac. So, when an app launches, I checked it that if a font is installed in mac or not with the below code. NSArray *fonts = [[NSFontManager sharedFontManager] availableFontFamilies]; if ([fonts containsObject:@"Square721 BT"]) { NSLog(@"Fonts Available"); } else { NSLog(@"No fonts"); } Now, if the font is not already installed, how can I install it programmatically? 回答1: Add

How to get rid of Enter Full Screen menu item?

余生颓废 提交于 2020-03-23 02:23:20
问题 In my Mac OS X app I deleted all default menu items, added my own. But in View menu at the bottom I can still see Enter Full Screen menu item, whilst in storyboard there is no such menu item. I've tried to delete the entire View menu, but now it migrated to Window menu. Even though it's disabled, I would still like to get rid of it entirely if possible. 回答1: The release notes for AppKit for 10.11 suggest you can use the NSUserDefault NSFullScreenMenuItemEverywhere . Full Screen Menu Item

Check OS version using Swift on Mac OS X

本秂侑毒 提交于 2020-03-21 14:23:34
问题 I'm building an application that needs to check what version of OS X is installed on a Mac. It is built against 10.9 Mavericks, but all of the Swift APIs are pretty much 10.10 only. I'm trying to use the following, however it does not compile against the 10.9 SDK since it does not have these APIs, I know how to use if #available(OSX 10.10, *) to conditionally compile as per the different versions, however because NSProcessInfo is a 10.10+ API I can't use it to check to see if the Mac is

How do I open another window in macOS in Swift with Cocoa

﹥>﹥吖頭↗ 提交于 2020-03-18 11:36:05
问题 I am working on a macOS app that presents a list of customer master records in a table view. Double-clicking a row in the table view should open a new window where the user can view and edit the customer information. This is an Xcode 8.3.3 project using a storyboard and Swift. It is not a document or core data app. I have the main window working up to the point where the table view is displaying the records correctly and the associated view controller is receiving the double-click events and

Hide, show annotation on MkMapView

吃可爱长大的小学妹 提交于 2020-03-17 07:29:47
问题 How to hide annotation when zooming out the map view. I have a big number of annotation i have to hide them because if the region displayed on the map is too big you can see only the annotations. 回答1: To do this, you have to check the size of your region, and depending of it you set the views hidden or not. I tested the code bellow but, you will probably need some adjustments. - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { NSArray *annotations = [_mapView

Show NSMenu only on NSStatusBarButton right click?

江枫思渺然 提交于 2020-03-16 07:15:31
问题 I have the following code: (can be copy-pasted to New macOS project) import Cocoa import SwiftUI @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var statusBarItem: NSStatusItem! func applicationDidFinishLaunching(_ aNotification: Notification) { let statusBar = NSStatusBar.system statusBarItem = statusBar.statusItem( withLength: NSStatusItem.squareLength) statusBarItem.button?.title = "🍎" // Setting action statusBarItem.button?.action = #selector(self

OSX drag and drop text ( not file ) to app dock icon

╄→尐↘猪︶ㄣ 提交于 2020-03-15 07:35:30
问题 I'd like to handle when user drag and drop text ( not file which contain text ) to my app's dock icon. How should i do that? 回答1: The easiest way to accept text dropped on the Dock icon is to implement a service that accepts text. In your Info.plist: <dict> <key>NSMenuItem</key> <dict> <key>default</key> <string>Search in HoudahSpot</string> </dict> <key>NSMessage</key> <string>search</string> <key>NSPortName</key> <string>HoudahSpot</string> <key>NSRequiredContext</key> <dict> <key

OSX drag and drop text ( not file ) to app dock icon

孤人 提交于 2020-03-15 07:35:08
问题 I'd like to handle when user drag and drop text ( not file which contain text ) to my app's dock icon. How should i do that? 回答1: The easiest way to accept text dropped on the Dock icon is to implement a service that accepts text. In your Info.plist: <dict> <key>NSMenuItem</key> <dict> <key>default</key> <string>Search in HoudahSpot</string> </dict> <key>NSMessage</key> <string>search</string> <key>NSPortName</key> <string>HoudahSpot</string> <key>NSRequiredContext</key> <dict> <key

OSX drag and drop text ( not file ) to app dock icon

安稳与你 提交于 2020-03-15 07:35:08
问题 I'd like to handle when user drag and drop text ( not file which contain text ) to my app's dock icon. How should i do that? 回答1: The easiest way to accept text dropped on the Dock icon is to implement a service that accepts text. In your Info.plist: <dict> <key>NSMenuItem</key> <dict> <key>default</key> <string>Search in HoudahSpot</string> </dict> <key>NSMessage</key> <string>search</string> <key>NSPortName</key> <string>HoudahSpot</string> <key>NSRequiredContext</key> <dict> <key