I have an older application that has a specific appearance based on NSCell-based NSTableView having Source List highlighting. Unfortunately, on Yosemite this adds the NSVisualEffectView vibrancy under the selected cell which breaks the appearance in an unpleasant way.
I can't find a way to opt-out of this behaviour, unfortunately.
Setting Regular highlighting breaks the appearance in another way (grey selection instead of blue).
Any idea if there is a way to opt-out of this behaviour on 10.10?
You need to change table view appearance from NSAppearanceNameVibrantLight to NSAppearanceNameAqua. If you're targeting OS X 10.8 or earlier try setting the appearance by editing XIB file directly:
<tableView appearanceType="aqua" ...>
Also make sure that table view background color is set to Default in IB.
I don't know if it works for your case, but the best way to disable an implicit visual effect view is to just embed your NSTable/OutlineView in another NSVisualEffectView and set that views state to inactive
visualEffectView.state = .inactive
Related
Prior to macOS Big Sur, I could create an NSOutlineView and hide the default show/hide arrows that expand and collapse groups of items. But now in Big Sur, I can't find any way to get rid of the default arrows. I'm using my own arrow style and functionality.
Here's a screenshot:
I have my NSOutlineView set to have a Plain Style since I also provide my own margins around the rows. But I don't see any options in the storyboard editor for hiding the arrows, nor do I see any options under NSOutlineView in the docs for doing it.
Does anyone know how to hide the default expand/collapse arrows in Big Sur?
A reliable way of customizing the disclosure button for NSOutlineView is to subclass NSOutlineView and override a couple key methods. First, override frameOfOutlineCellAtRow: to reposition the arrow where you want. Then, override makeViewWithIdentifier: to customize the view that actually implements the arrow. You can identify it with the identifier NSOutlineViewDisclosureButtonKey.
Achieving the goal in this way is probably both more reliable than however you were doing it before, and likely to be more consistent for technologies like accessibility screen readers.
With the OS X 10.10 SDK, NSPopover seems to default to including an NSVisualEffectView somewhere in its hierarchy. Trouble is, I can’t seem to find any way to manage the effect.
I’ve tried the Xcode View Debugger but that didn’t offer very much information:
Are we expected to be able to tweak this vibrancy or just accept it and move on?
I wouldn't mind being able to tweak the effect or change the appearance of certain items in the (apparently enforced) dark mode.
It appears that you need to set the NSPopover's appearance property to an instance of NSAppearance.
There are a number of standard appearances including both light and dark vibrancy, along with a allowsVibrancy property for custom appearances.
While the documentation for the vibrance appearances says:
This should only be set on an NSVisualEffectView or one of its subviews.
The NSPopover documentation doesn't appear to have been updated (the comment for appearance still references the NSPopoverAppearance enum), so it is probably worth a shot.
I'm new to Xcode (Mac development, not iOS), and for some reason I can't figure out how to even change any object's color (text, background or really anything). Every site seems to say to click on the object, go to the attributes inspector and all of those options are under 'view'. However, in my Xcode (5.1.1) all it shows under 'view' is tag, focus ring, drawing, and auto-resizing. Am I missing something obvious?
On OS X, NSView does not have an intrinsic backgroundColor property. Thus, you cannot set the color of a view from Interface Builder. You have to create an NSView subclass and override -drawRect: or -updateLayer to make it the color you want. Even then, that color will not show up in Interface Builder. (This changes in Xcode 6, which is still in beta as of this writing.)
Is this somewhat annoying? Yeah. But that's the way it is.
As for changing the text of an object, you should be able to do it from the Attributes inspector, but only if it's something that already has text (i.e. a text field, text view, or button). An arbitrary custom view does not have text, so you can't set it in Interface Builder.
You should easily be able to set the background color of whatever UI element you want programmatically.
[viewObject setBackgroundColor:[UIColor greenColor]];
As for editing a xib for OSX I'm not sure. I have only done iOS development.
I'm writing an OS X app and have a problem with font smoothing in separate window.
I have a text field where you put text and suggestion window which pops up with a list of suggestions according to what you wrote. I'm using View-cell based NSTableView to display those suggestions and SFBPopoverWindowController to display it as a "popup" window (tried other classes with the same effect). When rows are first drawn they look fine but after I select them (keyboard or mouse) the font changes it's weight. It's only visual - like you would change smoothing method on the font, not it's bold setting.
"Music note" is the selected cell here
What's even more strange is that after I hide and show the window 3 times everything works fine from that point on.
Again - "Music note" is the selected cell.
The selection is done by overwriting NSTableRowView class and its drawSelectionInRect: method but I tried with drawing everything inside custom NSTableCellView class and it didn't help. The text is standard NSTextField - nothing's changed there.
The SFBPopoverWindow (and it's controller) are created once and reused with styleMask NSBorderlessWindowMask, backing NSBackingStoreBuffered, defer set to YES. The only change in SFBPopoverWindowController I made was to turn off window becoming key window but it doesn't change anything.
It might be related to the way a table view draws it's selected cells (setSelectionHightLightStyle:). Try to set the style to None/ NSTableViewSelectionHighlightStyleNone in your code or IB / Storyboard-file and draw the selection yourself (in a NSTableRowView subclass).
Background: When you use NSTableViewSelectionHighlightStyleRegular or NSTableViewSelectionHighlightStyleSourceList the table view assumes that you use the standard selection behaviour and appearance and does some magic to support that.
==========
UPDATE
==========
My previous answer is still valid but since it only describes the problem and hints at a workaround, I wanted to add a real solution. If you want to use NSTableViewSelectionHighlightStyleRegular for your table view (with custom font and colors), you need a way to 'disable' the system magic that comes into place once your row is highlighted. One proposed solution is to decline the first responder status. It has a lot of drawbacks and isn't a good solution at all.
So, let's have a closer look at the system 'magic' that kicks in as soon as the row will be highlighted: NSTableRowView has a property interiorBackgroundStyle that is – according to the documentation – 'an indication of how the subviews should draw'. Furthermore 'This value is dynamically computed based on the set of properties set for the NSTableRowView. Subclassers can override this value when they draw differently based on the currently displayed properties. This method can also be called to determine what color a subview should use, or alternatively, NSControls can have the -backgroundStyle set on their cell to this value.'
I assume that this style will be handed down the subview hierarchy and causes your text fields to look odd. The system assumes that a highlighted cell has a dark background and changes the interiorBackgroundStyle to dark. Other controls try to adapt accordingly.
I think there are two solutions to this problem:
1) Override interiorBackgroundStyle in your NSTableRowView subclass and return the style that fits your interface (in my case it's .light because my highlight color is a very bright blue). This worked for me.
2) If changing the whole style is a bit too much because you only want certain elements to not change their style, you may only need to adjust these subclasses. I haven't tried this yet.
In older Xcode I have a little window where I could mark braces and band things to control how a NSView behaves when its parent is resized. In the new Xcode that is missing and the controls are doing whatever they feel like.
Is there any way to get this control back? (current version: Version 4.3.2 (4E2002))
Starting with Xcode 4.3 when you create a Cocoa application project, the xib file uses auto layout. Auto layout replaces the size inspector's autosizing mask.
If you want to use the autosizing mask, the solution is to turn off auto layout. Select the xib file from the project navigator, open the file inspector, and deselect the Use Auto Layout checkbox.
Read Constraints Express Relationships Between Views to learn how views are constrained in Xcode 4. In fact, you probably want the entire Cocoa Auto Layout Guide.
Briefly, when you add a view to your view hierarchy, it comes with some constraints. Select the view in the and you'll see some blue lines that look a bit like I-beams -- these represent the constraints. Click on one of them and you can edit its properties in the attributes inspector. But how you should set the attributes probably won't make much sense until you've read about how constraints work in the document linked above.