appkit

NSButton in Catalina has no selected state

陌路散爱 提交于 2019-11-28 00:50:24
问题 I have an NSButton set as a checkbox with the following code on Catalina (Mojave is fine): let checkbox = NSButton(frame: NSRect(x: 0, y: 0, width: 200, height: 32)) checkbox.setButtonType(.switch) checkbox.title = "Sustain" checkbox.state = .off self.view.addSubview(checkbox) It looks fine when I load the app But as soon as I check it, the tick mark that I expect to be there isn't there If I load up the visual hierarchy debugger I can see it fine, I've tried putting this code straight onto a

Borderless NSButton turns gray when clicked

怎甘沉沦 提交于 2019-11-27 12:39:00
I am making a little application with three NSButtons with an image set. These buttons have no border nor background. However, when I click a button it turns into a gray rectangle. How can I fix this? Thanks. Make your button type as NSMomentaryChangeButton . [myBtn setButtonType:NSMomentaryChangeButton]; If you use NSMomentaryPushInButton then you may get gray rectangle over the button when click. Sean Rich You should be able to adjust this by changing the state mask. To do so, check out the highlightsBy: and showsStateBy: properties of NSButtonCell - they are for setting the press effect and

How do I draw the desktop on Mac OS X?

大憨熊 提交于 2019-11-27 10:23:41
问题 I want to draw the desktop on Mac OS X (Snow Leopard). Specifically, I want to achieve the same effect as running: /System/Library/Frameworks/ScreenSaver.framework/Resources/ ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background (If you’re not near your computer, this displays the screensaver where you would normally see your desktop background.) I know how to make a window without a border (by subclassing NSWindow and overriding initWithContentRect:styleMask:backing:defer: to

How to get height for NSAttributedString at a fixed width

无人久伴 提交于 2019-11-27 09:50:26
问题 I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size , but the results are useless (for this purpose), as they'll give whatever width the string desires. Calling - (void)drawWithRect:(NSRect)rect options:(NSStringDrawingOptions)options with a rect shaped to the width I want and NSStringDrawingUsesLineFragmentOrigin in the options, exactly as I'm using in

UITextView – can't set underline or strikethrough attributes on text?

元气小坏坏 提交于 2019-11-27 07:37:39
问题 I'm getting runtime failures whenever I try to set underline or strikethrough attributes on the attributedText of a UITextView. Other properties, like font and background color have no problems. Here's a code snippet. All I have is a test project with a single UITextView. I'm on iOS 11. class ViewController: UIViewController { @IBOutlet weak var myTextView: UITextView! var myMutableString = NSMutableAttributedString(string: "") override func viewDidLoad() { super.viewDidLoad() let string =

Being apprised of when NSStatusItem is hidden

让人想犯罪 __ 提交于 2019-11-27 02:51:40
问题 I have an app which uses an NSStatusItem . On small screens there's not much space in the status bar. When a user switches to an application with a lot of menu items, my status item gets hidden. Is there a way to get notified about this? What I tried so far: I checked if any NSNotification is fired: No I checked if the statusView is removed from the view hierarchy: No I checked isHiddenOrHasHiddenAncestor : No Here's the code I use to create the status item. self.statusItem = [[NSStatusBar

Prevent selecting all tokens in NSTokenField

别等时光非礼了梦想. 提交于 2019-11-27 02:27:42
问题 Is there any way to prevent the NSTokenField to select everything when pressing the ENTER key or when making to the first responder maybe using the TAB key? 回答1: An NSTokenField is a subclass of NSTextField. There's no easy, direct way to directly manipulate the selection of these classes (aside from -selectText:, which selects all). To do this when it becomes the first responder, you'll need to subclass NSTokenField (remember to set the class of the field in your XIB to that of your custom

How to handle with a default URL scheme

北城以北 提交于 2019-11-26 19:47:39
I want to build URI (or URL scheme) support in my app. I do a LSSetDefaultHandlerForURLScheme() in my + (void)initialize and I setted the specific URL schemes also in my info.plist . So I have URL schemes without Apple Script or Apple Events . When I call myScheme: in my favorite browser the system activates my app. The problem is, how to handle the schemes when they are called. Or better said: How can I define what my app should do, when myScheme: is called. Is there a special method that I have to implement or do I have to register one somewhere? Thomas Zoechling As you are mentioning

Borderless NSButton turns gray when clicked

时间秒杀一切 提交于 2019-11-26 16:05:41
问题 I am making a little application with three NSButtons with an image set. These buttons have no border nor background. However, when I click a button it turns into a gray rectangle. How can I fix this? Thanks. 回答1: Make your button type as NSMomentaryChangeButton . [myBtn setButtonType:NSMomentaryChangeButton]; If you use NSMomentaryPushInButton then you may get gray rectangle over the button when click. 回答2: You should be able to adjust this by changing the state mask. To do so, check out the

How to handle with a default URL scheme

这一生的挚爱 提交于 2019-11-26 07:26:42
问题 I want to build URI (or URL scheme) support in my app. I do a LSSetDefaultHandlerForURLScheme() in my + (void)initialize and I setted the specific URL schemes also in my info.plist . So I have URL schemes without Apple Script or Apple Events . When I call myScheme: in my favorite browser the system activates my app. The problem is, how to handle the schemes when they are called. Or better said: How can I define what my app should do, when myScheme: is called. Is there a special method that I