nsview

Overlay NSScroller over content

依然范特西╮ 提交于 2019-12-03 09:57:25
问题 Is there any way to overlay the NSScroller over the content of the scroll view (like in iOS)? I've already tried several approaches: a) setting the frame of the scroll view content view (NSClipView) to extend into the bounds of the scroller b) adding an NSScroller object as a subview of the scroll view (positioned where I want) c) creating an entirely custom scroller view and placing it as a subview (this worked, but that would mean that I need to rewrite all the functionality of NSScroller)

Interface Builder: How to load view from nib file

家住魔仙堡 提交于 2019-12-03 08:37:57
I have a MyCustomView subclassed from NSView designed in a .xib. I would like to insert this view into some of my other xib's round my application. How should I do this? If i drag a custom view and change the class to MyCustomView, but that does not load my xib-file. Can this only be done programmatically or is there a way to do this inside interface builder? EDIT1: Here is a very small demo-project: http://s000.tinyupload.com/index.php?file_id=09538344018446482999 It contains the default MainMenu xib and my CustomView xib. I would like my CustomView.xib to be displayed inside the custom view

Distinguishing a single click from a double click in Cocoa on the Mac

耗尽温柔 提交于 2019-12-03 07:58:49
问题 I have a custom NSView (it's one of many and they all live inside an NSCollectionView — I don't think that's relevant, but who knows). When I click the view, I want it to change its selection state (and redraw itself accordingly); when I double-click the view, I want it to pop up a larger preview window for the object that was just double-clicked. My first looked like this: - (void)mouseUp: (NSEvent *)theEvent { if ([theEvent clickCount] == 1) [model setIsSelected: ![model isSelected]]; else

How can I get an NSView to resize to fit the desired sizes of its subviews using Auto Layout?

扶醉桌前 提交于 2019-12-03 07:49:54
问题 I have a superview with three subviews. Two of those subviews are fixed in size and position within the superview, but the third can vary in size depending on its contents. I have set up auto layout constraints to set the size and position of each of the sub views, but what I would like to happen is that when the contents of the third view change, the superview should resize to be able to display it fully. I have implemented - (NSSize) intrinsicContentSize on that subview so that it returns

How to use Swift playground to display NSView with some drawing?

拈花ヽ惹草 提交于 2019-12-03 06:02:12
Basically I would like to test a chart drawing in a Swift playground in NSView. Here is what I am using now: class CustomView: NSView { init(frame: NSRect) { super.init(frame: frame) } override func drawRect(dirtyRect: NSRect) { color.setFill() NSRectFill(self.bounds) NSColor.yellowColor().setFill() var r = NSMakeRect(0, y, self.bounds.width, 5) NSRectFill(r) } var color = NSColor.greenColor() var y: CGFloat = 0 } var view = CustomView(frame: NSRect(x: 0, y: 0, width: 300, height: 300)) view.color = NSColor.greenColor() XCPShowView("chart", view) for var i = 0; i < 100; ++i { view.y = CGFloat

Adding a custom view to toolbar

那年仲夏 提交于 2019-12-03 05:38:39
I'm struggling with Cocoa for 2 hours now without success. I want to add a custom view to the toolbar. So, I added a NSToolbar to the window (with IB), and added my view (which works perfectly). IB automatically created a NSToolbarItem. I followed the instructions from Apple here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Toolbars/Tasks/AddRemoveToolbarItems.html#//apple_ref/doc/uid/20000755-BBCGJCDJ The problem is that I don't know what to do now, the view doesn't show although it's label is displayed in the window. Here's the code I use to draw (very simple, it's

Rounded rect on NSView that clips all containing subviews

半世苍凉 提交于 2019-12-03 05:21:30
I am creating a NSView subclass that has rounded corners. This view is meant to be a container and other subviews will be added to it. I am trying to get the rounded corners of the NSView to clip all of the subview's corners as well, but am not able to get it. - (void)drawRect:(NSRect)dirtyRect { NSRect rect = [self bounds]; NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:self.radius yRadius:self.radius]; [path addClip]; [[NSColor redColor] set]; NSRectFill(dirtyRect); [super drawRect:dirtyRect]; } The red is just for example. If I add a subview to the rect, The

Repeating background image in an NSView

荒凉一梦 提交于 2019-12-03 05:18:09
问题 I am trying to draw a repeating background image in my NSView, I have this till now: // INIT - (id)initWithFrame:(NSRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundImage = [NSImage imageNamed:@"progressBackground.pdf"]; } return self; } // DRAW - (void)drawRect:(NSRect)dirtyRect { // Draw the background [backgroundImage drawInRect:[self bounds] fromRect:NSMakeRect(0.0f, 0.0f, backgroundImage.size.width, backgroundImage.size.height) operation:NSCompositeSourceAtop

any Cocoa control code that I can use that acts as a patch bay?

依然范特西╮ 提交于 2019-12-03 04:49:41
I would like to make a patch bay type control... any source online that anyone knows of that I could work from? Thanks sbooth The closest thing I'm aware of is EFLaceView: http://www.cocoadev.com/index.pl?FlowChartView Edit: EFLaceView seems to have disappeared, but I have a saved copy: EFLaceView Edit: Version of EFLaceView on github , with more recent changes than link above. Unless you can find someone online who is sharing exactly the kind of control you're looking for, you don't have any choice but to build this for yourself. For that, you need to understand Control and Cell Programming ,

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