nsview

Graying out an NSWindow's content

眉间皱痕 提交于 2019-12-05 18:31:00
I have an NSWindow with 2 NSViews (an NSSplitView and a custom NSView ). Accessing the data to populate these views can take some time. During this period, I'd like to gray out the content of these views. My first approach was to have a black third NSView that covered the other 2 and achieve the graying out effect by changing its alpha value. However I've since learned having a hierarchy with sibling views is undefined. What is the best approach here? Cache the NSBitmapImageRep of the 2 views, then replace them with the 3rd view, using the cached image(s) as background Set the alpha value for

Subclassing NSScrollView drawRect: Method

心已入冬 提交于 2019-12-05 14:49:31
I'm customizing the UI for one of my apps, and the idea is that a text area is initially bordered gray when out of focus, and when it comes into focus, the border becomes bright white. My app uses a dark theme, and for a single-lined NSTextField , this works great. I'm running into problems with a subclassed NSTextView , however. In order to alter the border properly, I ended up having to actually subclass the parent NSScrollView , but am still seeing strange behavior. (See screenshot below.) I want the red box to fill the entire scroll view, as this would allow me to stroke (instead of

rounded corners on NSView using NSBezierPath are drawn badly

给你一囗甜甜゛ 提交于 2019-12-05 11:38:59
In my ViewController's main NSView, I override the func drawRect(dirtyRect: NSRect) method to implement rounded corners on my main view using NSBezierPath . In that same method I also designate the gradient background of my main view. override func drawRect(dirtyRect: NSRect) { let path: NSBezierPath = NSBezierPath(roundedRect: self.bounds, xRadius: 18.0, yRadius: 18.0) path.addClip() let gradient = NSGradient(startingColor: NSColor(hexColorCode: "#383838"), endingColor: NSColor(hexColorCode: "#222222")) gradient.drawInRect(self.frame, angle: 90) } The problem that arises is illustrated in the

Layer-backed NSView performance with rendering directly in CALayer.drawInContext:

泄露秘密 提交于 2019-12-05 11:14:39
I have many layer-backed views contained in a NSScrollview and am predominantly concerned with scrolling performance . The documentView and higher are layer-backed hence their subviews are also layer-backed. The following are the three natural places that display/rendering code could go: override NSView.wantsUpdateLayer to return false (or don't do anything because this is the default) & do drawing in NSView's drawRect method override NSView.wantsUpdateLayer to return true & do drawing in NSView's updateLayer method do NO drawing in NSView at all & perform all drawing in CALayer's

Layering Cocoa WebView - Drawing on top?

旧城冷巷雨未停 提交于 2019-12-05 10:19:57
webview in core animation layer The only other thread I can find is the above which doesn't necessarily fit my needs. Is there a reliable way to simply draw a view on top of a webview? I've tried to layer a regular NSView on top of WebView, and it draws right at first, but any movement in the webview (scrolling the page etc) appears to invalidate the view and produces visual artifacts. I've tried: [[[NSApp mainWindow] contentView] addSubview:view positioned:NSWindowAbove relativeTo:webView]; No luck there, same problems -- z-ordering doesn't seem to work unless I'm missing something. Is this

Disable clicks on a NSView

我们两清 提交于 2019-12-05 07:08:40
I know that on a NSWindow you can use setIgnoresMouseEvents: . However, a NSView doesn't have either setEnabled: or setIgnoresMouseEvents: . Any fixes? Implement the hitTest: method to return nil . 来源: https://stackoverflow.com/questions/6543240/disable-clicks-on-a-nsview

Cocoa draw noise

三世轮回 提交于 2019-12-05 05:41:00
问题 Is it possible to draw some noise on top of a rect I filled using NSRectFill? I need to make my app that draws a custom title bar look wonderful on 10.7 before release, and to make it look a little more like iTunes. I would love if this is possible using no images, but if I have to include a PNG or something as a mask, I'd be fine with that. Thanks! 回答1: You can either use drawing logic (drawing a lot of small rects, lines or other polygons), or use NSImage's drawing methods, like for

Swift 3 Load xib. NSBundle.mainBundle().loadNibNamed return Bool

孤者浪人 提交于 2019-12-05 04:49:06
I was trying to figure out how to create a custom view using xib files. In this question the next method is used. NSBundle.mainBundle().loadNibNamed("CardView", owner: nil, options: nil)[0] as! UIView Cocoa has the same method,however, this method has changed in swift 3 to loadNibNamed(_:owner:topLevelObjects:) , which returns Bool , and previous code generates "Type Bool has no subscript members" error, which is obvious, since the return type is Bool. So, my question is how to a load view from xib file in Swift 3 First of all the method has not been changed in Swift 3 . loadNibNamed(_:owner

NSWindow launching with wrong size after setting contentViewController to NSTabViewController

浪子不回头ぞ 提交于 2019-12-05 02:00:15
问题 I have an Xcode project with an NSWindowController whose contentViewController was set to a subclass of NSViewController . I recently removed the NSViewController subclass from the storyboard and replaced the contentViewController with an NSTabViewController subclass. Now, when I run the application, the NSWindow opens with a size of 500x500 instead of the size of the first tab. What's more, there is no view I can see in the storyboard that has a size of 500x500, and that size isn't being

Adding border and Rounded Rect in the NSView

我是研究僧i 提交于 2019-12-05 01:12:41
In my Application , NSView should have rounded rect and border, i tried following static CGColorRef CGColorCreateFromNSColor (CGColorSpaceRef colorSpace, NSColor *color) { NSColor *deviceColor = [color colorUsingColorSpaceName: NSDeviceRGBColorSpace]; float components[4]; [deviceColor getRed: &components[0] green: &components[1] blue: &components[2] alpha: &components[3]]; return CGColorCreate (colorSpace, components); } and in InitWithframe added following lines of Code [[self layer] setCornerRadius:505]; [[self layer] setBorderWidth:500.0]; CGColorSpaceRef colorSpace =