appkit

Vertically aligning text in an NSTextField using Swift

筅森魡賤 提交于 2019-12-03 12:06:12
I have been reading through the various options on how to set the vertical alignment on an NSTextField. I want the text to be displayed in the center and to do it programatically in Swift. Here are the things I have looked so far: http://www.cocoabuilder.com/archive/cocoa/174994-repositioning-an-nstextfieldcell.html https://red-sweater.com/blog/148/what-a-difference-a-cell-makes Vertically Centre Text in NSSecureTextField with subclassing Get NSTextField contents to scale vertically align text in a CATextLayer? One thing I have tried in Swift is to set the following property: textField

The most elegant way of creating a fullscreen overlay on Mac OS X (Lion)?

蹲街弑〆低调 提交于 2019-12-03 09:30:33
问题 I'm searching for the "best" way of creating a fullscreen overlay under Mac OS X. I want to create a transparent or semi-transparent overlay, which cares about mouse events and shows other input/output elements. This overlay should be above every other GUI items (like the CMD-Tab overlay). Do you know how to do it effectively? At the moment I'm playing around with this kind of code: int windowLevel = CGShieldingWindowLevel(); NSRect windowRect = [[NSScreen mainScreen] frame]; NSWindow

How to make NSView not clip its bounding area?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 03:02:30
I created an empty Cocoa app on Xcode for OS X, and added: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.view = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 200, 200)]; self.view.wantsLayer = YES; self.view.layer = [CALayer layer]; self.view.layer.backgroundColor = [[NSColor yellowColor] CGColor]; self.view.layer.anchorPoint = CGPointMake(0.5, 0.5); self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 1, 1, 1); [self.window.contentView addSubview:self.view]; } But the rotated layer's background is clipped by the view's bounding area: I

The most elegant way of creating a fullscreen overlay on Mac OS X (Lion)?

你。 提交于 2019-12-02 23:53:42
I'm searching for the "best" way of creating a fullscreen overlay under Mac OS X. I want to create a transparent or semi-transparent overlay, which cares about mouse events and shows other input/output elements. This overlay should be above every other GUI items (like the CMD-Tab overlay). Do you know how to do it effectively? At the moment I'm playing around with this kind of code: int windowLevel = CGShieldingWindowLevel(); NSRect windowRect = [[NSScreen mainScreen] frame]; NSWindow *overlayWindow = [[NSWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing

NSSharingService to send email and read email body

时光毁灭记忆、已成空白 提交于 2019-12-02 16:09:50
问题 I am using NSSharingService to bring up an email compose window in the Mail app: NSSharingService* sharingService = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail]; [sharingService setRecipients:@[@"test@blahblah.com"]]; [sharingService setSubject:@"Test"]; sharingService.delegate = self; It brings up the compose email window fine, and when I enter in some text and actually send the email, I even get a callback to the delegate: - (void)sharingService:(NSSharingService

NSSharingService to send email and read email body

会有一股神秘感。 提交于 2019-12-02 10:56:01
I am using NSSharingService to bring up an email compose window in the Mail app: NSSharingService* sharingService = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail]; [sharingService setRecipients:@[@"test@blahblah.com"]]; [sharingService setSubject:@"Test"]; sharingService.delegate = self; It brings up the compose email window fine, and when I enter in some text and actually send the email, I even get a callback to the delegate: - (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items { NSLog(@"sharingService didShareItems - %@",

OSX NSTextField with layer background color not working

好久不见. 提交于 2019-12-02 05:18:46
问题 I have the following subclass of NSTextField (with corresponding subclass of NSTextFieldCell for spacing [approach found here]). I'm trying to change the border color and background color on "focus", but it isn't working. class TGTextField: NSTextField { override func viewWillDraw() { self.layer?.borderWidth = 1 self.layer?.cornerRadius = 2 self.textColor = NSColor(calibratedRed: 55/255, green: 54/255, blue: 54/255, alpha: 1) self.focusRingType = .None self.font = NSFont(name: "ProximaNova

OSX NSTextField with layer background color not working

梦想的初衷 提交于 2019-12-02 03:04:33
I have the following subclass of NSTextField (with corresponding subclass of NSTextFieldCell for spacing [approach found here ]). I'm trying to change the border color and background color on "focus", but it isn't working. class TGTextField: NSTextField { override func viewWillDraw() { self.layer?.borderWidth = 1 self.layer?.cornerRadius = 2 self.textColor = NSColor(calibratedRed: 55/255, green: 54/255, blue: 54/255, alpha: 1) self.focusRingType = .None self.font = NSFont(name: "ProximaNova-Medium", size: 16)! setBlurredStyles() } private func setFocusedStyles() { self.layer?.borderColor =

NSProgressIndicator in NSMenuItem not updating on second display

随声附和 提交于 2019-12-02 02:05:31
I've got a NSMenu attached to a NSStatusItem (a menu bar application). While downloading a file I want to display a NSProgressIndicator in an item of this menu. I've created a NSViewController subclass for this progress indicator with the following properties: @property NSUInteger current; // Bound to NSProgressIndicator value @property NSString *status; // Bound to a NSTextField value @property NSUInteger total; // Bound to NSProgressIndicator max value When needed I start the download of the file with the following code, which runs in NSRunLoopCommonModes so that the delegate methods are

How can you implement the NSDocument method -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: in Swift?

为君一笑 提交于 2019-12-01 21:06:08
问题 In my application, a NSDocument subclass mission-critical hardware – users really don’t want to close a document by accident! So, I’ve implemented canCloseDocumentWithDelegate… to show an NSAlert and ask before closing. I am now trying to implement this same thing in an application written in Swift. Since the answer comes asynchronously, the “should close” result is passed to a callback on a delegate, and not simply returned. In the documentation for -canCloseDocumentWithDelegate