cocoa

NSTimeInterval to readable NSNumber

帅比萌擦擦* 提交于 2020-01-04 01:52:27
问题 NSTimeInterval == double; (e.g. 169.12345666663) How can I round up this double so that there are only 2 digits left after the "dot"? It would be very good if the result is a NSNumber. 回答1: If this is for display purposes, take a look at NSNumberFormatter. If you really want to round the double in your calculations for some reason, you can use the standard C round() function. 回答2: A NSDecimal can be rounded to a specified number of digits with NSDecimalRound(). double d = [[NSDate date]

How do you make a Java app with a Cocoa UI?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 00:06:34
问题 I have to use a Java API for a project, but since I'm not a fan of Java UIs and I have a Mac, I want to build a native Cocoa application around the Java code. I know Xcode used to provide direct support for this sort of thing, but since it no longer does, what's the best way to do this? If it matters, I have Xcode 3.2.5 under Mac OS 10.6.8. 回答1: According to this Apple tech note it should be possible to launch a JVM from within your native Mac application. This article was originally written

How to change font size of NSTableHeaderCell

China☆狼群 提交于 2020-01-03 21:08:11
问题 I am trying to change the font size of my NSTableView within my code to allow the user to change it to their liking. I was successful by changing the font size of each NSTableCellView but failed to do so by the header cells. I was trying to do it like this let headerCell = NSTableHeaderCell() let font = NSFont(name: "Arial", size: 22.0) headerCell.stringValue = "firstname" headerCell.font = font customerTable.tableColumns[0].headerCell = headerCell The stringValue of the header cell will be

Cocoa Won't Capture Shift Modifier?

青春壹個敷衍的年華 提交于 2020-01-03 20:58:13
问题 I have an application in which I'm trying to capture the shift key modifier to perform an action, however when I run the program and press and normal key without the shift key modifier I get a beep and the modifier and key are not sent to my keyDown event. The relevant code is: NSString* eventChars = [theEvent charactersIgnoringModifiers]; if ([eventChars isEqualTo:@"w"]) { newPlayerRow++; direction = eUp; } else if ([eventChars isEqualTo:@"x"]) { newPlayerRow--; direction = eDown; } else if

Changing the background color of the unified NSToolbar (in Yosemite)

天大地大妈咪最大 提交于 2020-01-03 19:09:11
问题 I want to have a unified toolbar and therefore I found this post: How can I create Yosemite-style unified toolbar in Interface Builder? self.window.titleVisibility = NSWindowTitleVisibility.Hidden works perfect. But is there a way to change the background color for the toolbar? I tried with self.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark) , but this only brings a complete black toolbar (that's too dark). I want to have a custom color. 回答1: This one works: https:/

Changing the background color of the unified NSToolbar (in Yosemite)

依然范特西╮ 提交于 2020-01-03 19:08:08
问题 I want to have a unified toolbar and therefore I found this post: How can I create Yosemite-style unified toolbar in Interface Builder? self.window.titleVisibility = NSWindowTitleVisibility.Hidden works perfect. But is there a way to change the background color for the toolbar? I tried with self.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark) , but this only brings a complete black toolbar (that's too dark). I want to have a custom color. 回答1: This one works: https:/

NSView does not receive mouseUp: event when mouse button is released outside of view

a 夏天 提交于 2020-01-03 18:43:06
问题 I have a custom NSView subclass with (for example) the following methods: override func mouseDown(with event: NSEvent) { Swift.print("mouseDown") } override func mouseDragged(with event: NSEvent) { Swift.print("mouseDragged") } override func mouseUp(with event: NSEvent) { Swift.print("mouseUp") } As long as the mouse (button) is pressed, dragged and released all inside the view, this works fine. However, when the mouse is depressed inside the view, moved outside the view, and only then

NSView does not receive mouseUp: event when mouse button is released outside of view

一世执手 提交于 2020-01-03 18:43:01
问题 I have a custom NSView subclass with (for example) the following methods: override func mouseDown(with event: NSEvent) { Swift.print("mouseDown") } override func mouseDragged(with event: NSEvent) { Swift.print("mouseDragged") } override func mouseUp(with event: NSEvent) { Swift.print("mouseUp") } As long as the mouse (button) is pressed, dragged and released all inside the view, this works fine. However, when the mouse is depressed inside the view, moved outside the view, and only then

Using OpenSSL cocoa pod in iOS project

久未见 提交于 2020-01-03 18:37:10
问题 I'm trying to import OpenSSL pod header files into my iOS project. However, Xcode cannot find OpenSSL header. It says #import <OpenSSL/bio.h> OpenSSL/bio.h file not found But I was able to command + click to jump to the bio.h The OpenSSL pod is installed successfully and my PodFile is like below platform :ios, '9.0' use_frameworks! target 'MyProject' do pod 'OpenSSL', '~> 1.0' end using Xcode 7.2 Edit I have tried clean, build and delete Derived Data folder but still not working. 回答1: 1) I

calculating directory size in cocoa

假装没事ソ 提交于 2020-01-03 17:19:14
问题 I want to calculate the directory (folder)size and i have to list all files and folders (subfolders) in a volume(drive) with its corresponding size.I am using the below code to calculate size.The problem with this code is the performance issue . I am using NSBrowser to display . NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil]; NSEnumerator *filesEnumerator = [filesArray objectEnumerator]; NSString *fileName; unsigned long long int fileSize