天道酬勤,学无止境

cocoa

How to access accessibility settings in MacOSX Cocoa app using swift?

I'm pretty confused. Usually in an iOS app I would access the settings using a url scheme. Now I found out that on MacOSX using Objective-C you can do this: NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES}; BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options); I've tried to convert this to Swift but didn't got to a valid result. Does anyone know how to convert this or a valid method to ask for assistive access in Swift?

2021-06-14 17:11:45    分类:问答    objective-c   swift   macos   cocoa   permissions

Difference between innerhtml and outerhtml in cocoa WebView

I am using cocoa webview for rich text editing in my application. Just confused with innerHtml and outerHtml method avaiable in webkit. Can anyone explain what is the difference between [(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerHTML]; AND [(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText];

2021-06-14 16:55:03    分类:问答    objective-c   macos   cocoa   webview

Why do my xcode builds always go to the iPad simulator instead of the iPhone simulator?

I just installed the latest SDK from Apple so I can start learning iPhone / iPad app development. However, I'm having a stupid issue: all my builds get run in the iPad simulator instead of the iPhone simulator, and I have no idea how to change it.

2021-06-14 16:48:55    分类:问答    iphone   xcode   cocoa   ipad

Using NSTask and NSPipe causes 100% CPU usage

I'm trying to run a simple bash script using NSTask and direct the output to a text view. Once the task is executed, the CPU usage of my app is 100%, even though it's a simple echo (for now). I created a completely fresh project to isolate the issue: @interface AppDelegate () @property (nonatomic) NSTask *task; @property (nonatomic) NSPipe *pipe; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.pipe = [NSPipe pipe]; self.pipe.fileHandleForReading.readabilityHandler = ^(NSFileHandle *h) { NSLog(@"Read: %@", [h readDataToEndOfFile]); }

2021-06-14 16:26:21    分类:问答    objective-c   macos   cocoa   nstask   nspipe

NSAttributedString in TextField changing/resetting on click

I'm following THIS guide from apple, but it's not really working properly. Basically, I'm trying to add a hyperlink to an NSTextField within a Window, via a custom WindowController class. I'm able to get the hyperlink working with a few problems: When I hover over the hyperlink I get an 'I bean' (the cursor that indicates you can select text). I want a hand that normally appears over hyperlinks When I click on the hyperlinked text, it opens up the link in my browser successfully, but then it changes the text size and format (e.g. it is no longer centered, back to some default). Now when I

2021-06-14 15:53:18    分类:问答    objective-c   macos   cocoa

Embed Collection View in Custom Table View Cell

I have a table view with a custom Cell which gets it contents from an array, this all builds fine. I want to add to this content a Collection View of thumb nail images of varying number to each of the custom Table View Cells. I have added the Collection to the Custom Cell in the Story Board. I have linked the Collection to the Custom Cell.m (not sure it should go there). I have created a Collection Custom Cell and linked the image in. It is from here I am not sure, should the methods for building the collection view be placed in the the Custom Table Cell.m OR in the View Controller.m? I have

2021-06-14 15:23:42    分类:问答    xcode   cocoa   tableviewcell

Finding text's bounding rect in Core Text

I'm trying to find the boundaries of a line of text in Core Text. For simplicity, assume it has a single character. At the moment I'm using the following method: line = CTLineCreateWithAttributedString(attrString); rect = CTLineGetImageBounds(line, context); It works most of the times, but for some characters, like math italic d (Unicode: 0x1D451) or math italic q (Unicode: 0x1D45E), the width is a bit short. I tried using CTLineGetTypographicBounds() or CTFramesetterSuggestFrameSizeWithConstraints, but they didn't help either (I think they use glyph's advance to find the width, not its

2021-06-14 14:17:01    分类:问答    cocoa   cocoa-touch   macos   core-text

Mouse Events Bleeding Through NSView

I have an NSView which covers its parent window's content view. This view has a click event handler which removes it from the content view. Inside this view, I have another view. When I drag the mouse in this inner view, the mouse events are applied not only to the view in the front, but also to the views behind. Additionally, the cursors from the views behind are showing up as well. This is the same problem occurring here: NSView overlay passes mouse events to underlying subviews? but the answer there won't work for my project because I can't open another window.

2021-06-14 13:25:40    分类:问答    cocoa   nsview   nsevent

Show Window without activating (keep application below it active)

I need to show a window (without title bar) above third party applications without my window taking focus. I have tried using an NSPanel and setting enabling non-activating, but that didn't help. I tried orderFront:self, but that didn't help either. I always needed to add [NSApp activateIgnoringOtherApps:YES]; because the window wouldn't show otherwise. I have here a sample project for just this functionality: http://users.telenet.be/prullen/TopW2.zip UIElement is set to true in the application's plist file, so there is no dock. You can activate the window by pressing ALT + SPACE at the same

2021-06-14 12:51:50    分类:问答    objective-c   cocoa   nsview   nswindow   nswindowcontroller

Technique on how to format/color NSTextView's string

I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. Some code snippets on how I make a text bold [[textView textStorage] beginEditing]; [[textView textStorage] applyFontTraits:NSFontBoldTrait range:range]; [[textView textStorage] endEditing]; This and also the size changes with [[textView textStorage] beginEditing]; NSFont* font = [[textView textStorage] attribute:NSFontAttributeName atIndex:range.location effectiveRange:nil]; NSFont*

2021-06-14 12:33:59    分类:问答    cocoa   string-formatting   nstextview   nsattributedstring