NSTextView with clear background have phantom text - cocoa

I want to implement a textview with transparent background to show subtitles.
When I set Window backgroundColor = .clear, disable NSTextView draw background, then I change NSTextView.string as you can see in the following picture, previous text retain in the background
phantom text image
How can I clear the background text (Foo1245 in the image background) when change NSTextView.string ?
POC code is here POC

Did you read: How to implement NSTextFinderClient protocol in NSTextView in Swift? ?
Are you calling textFinder.noteClientStringWillChange() or textFinder.performAction(.HideFindInterface) when you change the NSTextView.string ?

Related

Access Default Window Color Cocoa

I have an SKView with a picture of a keyboard in a window as shown below. I would like the background color of the SKScene it's presenting to be the same color as the window behind it, so that it would appear as if the keyboard was just in the window, and not in something else that was in the window. After consulting the NSColor documentation, I tried setting the background color of the SKScene as NSColor.windowBackgroundColor(). The color below is what I got. I'm assuming there was some kind of error and so it defaulted to black. That being said, how do I access the default color of a window?
Set the SKView's allowsTransparency to true and then set the SKScene's backgroundColor to NSColor.clearColor().
I think that using windowBackgroundColor() gives black if the view doesn't allow transparency and works if it does because it's effectively being translated to clearColor() by "accident". windowBackgroundColor() is a bit strange. It's not in either an RGB nor a gray-scale color space and it can't be converted to either of those. I'm guessing that SKScene tries to convert the background color to the RGB color space and, when that fails, it uses clearColor() as a fallback.

NSTextField draws partially transparent text when drawsBackground = YES

I have an NSTextField. I want it to draw text and have a background color. But when I set drawsBackground to YES, the text seems to draw partially transparently. For example, if I set the text color to white and background to black, the text comes out gray. Why is this?
Make sure isEnabled set to true.
I was seeing this as well and changing this fixed it for me.

UILabel Transperent Text to see thru its subviews

I want to have a functionality of transparent text in UILabel I have seen one sample called named RSMaskedLabel. For label I am using OHAttributed label to use some extended functionality. So I merged some code of RSMaskedLabel to OHAttributed label's drawTextInRect method. Now I can see background image from label text. But what if I want to change that text color, set alpha of that masked text? I am giving some screenshot of FontCandy app. I want exact functionality like that app to write text on the image. I tried a lot since last 70 hours but no luck till now. if someone wants then I can upload my demo what I have done till now. please help..
add another UILabel with same frame of your label and and add your your label over that label set super view label background as clear set text colour as you want with alpha value.
with the font slider change alpha value of colour of super view label

how to implement the NSToolbarItem Animation like evernote

I want to implement an animation which is like the sync animation of evernote app on Max OS X.
The button looks like:
When the animation runs, only is the white arrow rotating.
I tried to use Core Animation, and the steps are following:
1 I dragged a NSButton to the tool bar and set it to an outlet aBtn. I set the blue blackground image to the aBtn.
2 I created a CALayer instance variable aLayer and add it to the aBtn. So it can look like the button above.
3 when aBtn was clicked, I add the rotation animation the aLayer. It run perfectly well.
The problem is when I want to customize the tool bar, the aBtn shown in the tool bar palette didn't have the aLayer and only had the blue background image.
Then I tried to find the event or notification for the showing or closing of the tool bar palette. As a result I can reset the image of the aBtn before the tool bar palette was shown or hidden.However, I couldn't be notified when the tool bar palette was closed.
Could any one give any suggestion?
If you have good idea about how to implement this animation, please let me know.
Thanks!
I create a gif to store the animation, and create an NSImageView for the gif. Then I use -[NSToolBarItem setView:].
Using gif is an easier way than implementing it with Core Animation.

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