How to get the vibrant effect for a NSTextField/NSSearchField like Safari's address bar in Big Sur - cocoa

I have a Mac app with a search field in its toolbar (actually a NSTextField, but I tried NSSearchField as well).
My problem is that the text field background on Big Sur is just plain white, which makes it hard to recognize.
Safari's location bar on Big Sur has more contrast. I believe this is somehow achieved by using vibrancy (How to change background color of NSSearchField (like in Messages app in OS X)), but I cannot get the same effect.
I tried:
testTextField.appearance = NSAppearance(named: .vibrantLight)
various combinations of drawing/not drawing backgrounds
various background colors
wrapping my toolbar item into NSVisualEffectView, but that shows around the text field
Edit:
I should mention that I use roundedBezel border style. This alone seems to affect the background color (i.e. background is always white, no matter which color was set).

Related

Get current tint for Desktop Tinting in macOS 10.14 Mojave

I am trying to read the current value of the tint applied in macOS 10.14 Mojave, and subscribe to updates. The color will update with the background image when you are in Dark mode and the Graphite color accent is not selected.
I would expect to be able to read it from NSColor.windowBackgroundColor, but the stored color does not seem to change, despite changes to what is on screen.
If you mean the behind-window tint that is applied to the window background, there doesn't seem to be a way to get that since it's location dependent: drag your window over a light and a dark background and see how that shines through as you move your window. The actual color is computed by the window compositing system.
Since you refer the "stored color", if you mean the CGColor and notice that this doesn't change as you switch from light to dark mode or vice versa, you may need to explicitly set the appearance first:
let saved = NSAppearance.current()
NSAppearance.setCurrent(someView.effectiveAppearance)
// Here you can access the "true" colors (minus vibrancy/compositing effects):
let cgColor = NSColor.windowBackgroundColor.cgColor
NSAppearance.setCurrent(saved)
This is necessary when working outside a drawRect: method (which automatically sets up the current appearance for you).

tvOS - UITextField shows white on white when focused

I've created a UITextField on a screen using a custom font (Skia 100 point) and sitting on top of a UIImageView, but otherwise it is quite unremarkable. When it's not focused, the text shows normally, if a bit faint:
When it is focused, however, the entire area renders as a solid white rectangle:
I'd be willing to compromise on the look and feel of this screen if I could get it to render normally when focused, but nothing I've tried has changed it--I always get white-on-white. I read about a similar issue where they said this was due to custom background colors but I have not set a background color. In fact, even if I set a custom text color, it does not seem to take effect--it looks the same.

LongListSelector Foreground Color

Have been searching through here with no luck, Pretty simple problem, On my emulator all font colors are white (which is what I want).
Testing on a device the fonts are all black now, I have managed to change this by setting the foreground colors on the elements however I am unable to do so on the longlistselector through code.
This works for me:
longListSelector.Background = new SolidColorBrush(Colors.Transparent);
However this has no effect:
longListSelector.Foreground = new SolidColorBrush(Colors.White);
Any other way I can attempt to set the text color on the longlistselector?
The reason foreground colors would be different would be because of the default style. PhoneAccentBrush changes based on if your "phone" is set to have a white background or a black one.
The reason why your longListSelector.Foreground is not working may be because the phoneaccentbrush is set on the items inside the longlistselector from a style?

Why does this text look "less bold" in OS X 10.5 compared to 10.7?

I built a very simple application with nothing but a single NSTextView in it in xcode / interface builder. I've done nothing to the text view other than change the font face to "Arial" and increase the font size. However, it looks a lot less bold on OS X 10.5 than it does on 10.7. What's going on here?
(10.5 in the top window, 10.7 in the bottom window)
I've tested with Helvetica and got the same results, so it's not something to do with this specific font.
If you enlarge that image enough, you'll see color fringing on the 10.7 sample. This indicates that the text was rendered with subpixel antialiasing, more specifically, using a RGB subpixel ordering. The 10.5 sample uses grayscale antialiasing. While it is generally a good idea to use subpixel rendering, it can look bad on low-resolution screens or CRTs, and it can't be used in a multi-monitor setup where there is more than one subpixel arrangement to contend with. This means that some users will have subpixel rendering enabled for their system, and some won't. Don't try to circumvent that setting in any way, either by overriding the system preference for font smoothing, or by pre-rendering the text into an image. Users are far more likely to notice the one app whose text looks wrong on their system than they are to notice the difference in rendering between two different machines.

Add shadow (recessed text effect) to Cocoa label without degrading text rendering quality

I'd like to create statusbar with text effect like in Safari or iTunes, i.e. recessed text.
However, if I simply add shadow in Interface Builder using Core Animation panel, OS X's worst text rendering kicks in:
What's the trick to get recessed text on a label and keep proper subpixel rendering?
There is a built-in way to do this:
[[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
It's a cheap old trick: You draw the text in white at an offset and then draw the black text on top of it.
There is a hook for shadows in the text-drawing system, NSAttributedString's NSShadowAttributeName. But testing this out, it appears to kill the subpixel antialiasing as well.

Resources