nsview

How to detect right and left click in cocoa

天涯浪子 提交于 2019-12-18 12:47:36
问题 I want to create a action on right and left click of mouse. Click may be on NSTableViewCell, NSView, etc (Like when we right click on window it gives a pop-up ) . Is there any API to do such task? If no, any other way . Thank you in advance for helping me. 回答1: You have to override NSResponder methods like: - (void) mouseDown: (NSEvent*) theEvent; - (void) rightMouseDown: (NSEvent*) theEvent; Reference: NSResponder Documentation. Update: as mentioned below, NSView and NSTableView inherits

Subclassing NSView to have a transparent background

♀尐吖头ヾ 提交于 2019-12-18 04:45:07
问题 I am creating an app where I need to have a transparent NSView with a transparent PNG image inside. The problem is, the NSView I'm drawing has a gray background on it. I have it subclassed (as TransparentRectangleView) but don't know what to put in drawRect to make it transparent. I have already overridden the isOpaque method to return NO but it doesn't seem to help... Alternatively, is there already a subclassed NSView that is similar to the iPhone's UIImageView (as long as I can add

Selection Highlight in NSCollectionView

好久不见. 提交于 2019-12-17 17:37:23
问题 I have a working NSCollectionView with one minor, but critical, exception. Getting and highlighting the selected item within the collection. I've had all this working prior to Snow Leopard, but something appears to have changed and I can't quite place my finger on it, so I took my NSCollectionView right back to a basic test and followed Apple's documentation for creating an NSCollectionView here: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CollectionViews

How can I create Yosemite-style view with translucent/blurry background?

空扰寡人 提交于 2019-12-17 17:27:10
问题 In Yosemite sidebars have a semitransparent "vibrant" background. How can I create a view like that in 10.10/Xcode 6? Can I give any view such background? I've found that NSOutlineView will default to such background when you give it "Source list" highlight style, but the sidebar in the Calendar.app doesn't appear to be an NSOutlineView, so I wonder if there's a generic solution for this. 回答1: With the introduction of the Yosemite version of the OSX operating system, Apple introduced a new

Embed font in a mac bundle

孤者浪人 提交于 2019-12-17 06:27:26
问题 I have a program I am writing. I want to use a fancy font. Can I just embed my font into my bundle and use it from there. My code... NSMutableAttributedString *recOf; recOf = [[NSMutableAttributedString alloc] initWithString:@"In Recognition of"]; length = [recOf length]; [recOf addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Edwardian Script ITC" size:50] range:NSMakeRange(0, length)]; [[NSColor blackColor] set]; p.x = (bounds.size.width/2)- (([recOf size].width)/2); p.y =

Best way to change the background color for an NSView

女生的网名这么多〃 提交于 2019-12-17 02:42:05
问题 I'm looking for the best way to change the backgroundColor of an NSView . I'd also like to be able to set the appropriate alpha mask for the NSView . Something like: myView.backgroundColor = [NSColor colorWithCalibratedRed:0.227f green:0.251f blue:0.337 alpha:0.8]; I notice that NSWindow has this method, and I'm not a big fan of the NSColorWheel , or NSImage background options, but if they are the best, willing to use. 回答1: Yeah, your own answer was right. You could also use Cocoa methods: -

Save NSView representation ignores transparency

会有一股神秘感。 提交于 2019-12-13 15:42:00
问题 I am trying to change the icon of a file to a representation of an NSView . I am using the following code to do so. [mainDisplay lockFocus]; NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[mainDisplay bounds]]; [mainDisplay unlockFocus]; NSImage *image = [[NSImage alloc] initWithData:[rep representationUsingType:NSTIFFFileType properties:nil]]; [[NSWorkspace sharedWorkspace] setIcon:image forFile:[savePanel filename] options:0]; This works. It changes the icon

How to update NSImageView using NSSlider?

淺唱寂寞╮ 提交于 2019-12-13 09:25:14
问题 I have an NSSlider in FirstViewController . I have 12 NSImageViews in SecondViewController . I'd like to move a slider in first window and shuffle images in these 12 views in second window. How to update these NSImageViews every time when moving the slider? SecondViewController var imagesQty = 100 override func viewWillAppear() { super.viewWillAppear() //let arrayOfViews: [NSImageView] = [view01,...view12] for view in arrayOfViews { let i = Int(arc4random_uniform(UInt32(imagesQty-1))) let

NSView leaves artifacts on another NSView when the first is moved across the second

北城以北 提交于 2019-12-13 06:16:13
问题 I have an NSView subclass that can be dragged around in its superview. I move the views by calling NSView's setFrameOrigin and setFrameRotation methods in my mouseDragged event handler. The views are both moved and rotated with each call. I have multiple instances of these views contained by a single superview. The problem I'm having is that, as one view is dragged over another, it leaves artifacts behind on the view it's eclipsing. I recorded a short video of this in action. Unfortunately,

Using getRectsBeingDrawn: with Swift

安稳与你 提交于 2019-12-13 03:37:14
问题 I'm trying to use the NSView call getRectsBeingDrawn(_:count:) in a Swift app, but can't fathom how to unpack the 'return' values - the method's signature is particularly arcane. I'm getting the expected number of rectangles via the count variable, but I've no idea how to get access to rectangles in the array. This question addresses the same issue, and proposes a solution, but it's not working for me - I can't get access to NSRect structs. func decideWhatToRedraw() { let r1 = CGRect(x: 0, y: