Glow around Button - cocoa

How can I draw a slight white 'glow' around a button or label in 10.5 and later? I have seen some apps do it, but I am still confused how I should do this.

See NSShadow. You'd create and set a shadow (saving your graphics context beforehand), then draw the basic shape of your button, unset it (by restoring your graphics context), then continue drawing as usual.
In the case of a ready-made control like NSButton, you will need to subclass and override its cell drawing (and possibly make the host NSButton control itself a bit larger to accommodate the larger area needed to encompass the "glow" of the cell).
You might be able to avoid this with a label by setting its font shadow, but I don't think IB lets you do this, so you'd programmatically give the label an attributed string (via its -setAttributedString: method). The attributes would include the NSShadow (configured as desired) as the NSShadowAttributeName.

Related

how to make a single line text used as a glyph(mac develop)

Effect like the mac mail app,this image is a screenshot
how can i get effect like that. I try the cocoa text system,and don't find some useful things.
and I use the nstextattachment with textatttachmentcell initImageCell,obtain some effect like that,but it is not good,it is not very nature.
please some one give directions to me.
Those objects are not glyphs, they are controls, such as a subclass of a button. Custom controls have a drawing routine, which you override to draw a blue rectangle with round corners (a bezier path is the most flexible way to do so), then you draw the text (including the caret character) centered in the blue rectangle. Finally, handle the mouse events to do what you need to do when the control is clicked, such as popping up a menu in the right location.

Hiding Titlebar in NSWindow, rounding the corners and keeping the shadow

I like the way the developers behind Vox.app have created a custom titlebar and still kept the original shadow.
If you set the styleMask = NSBorderlessWindowMask it will create another kind of shadow, and the rounded corners are gone.
And it doesn't seem to be that easy to recreate those shadows especially when you also want rounded corners.
I have taken a window shot of the app that I like. Look at the drop shadows and the title bar.
Is it possible (I assume) to do this? And if so, how?
Is it possible (I assume) to do this?
Yes, this is possible.
And if so, how?
You need to subclass the NSWindow and NSView, set the background color, use custom buttons etc.
For curvy-corners, you need to draw using bezier path. I tried reached somewhat near, however titlebar's color is not changed in this screenshot... but I hope you can do it from here:

NSSegmentedControl with bold, italic, and underlined segment

I'm trying to build a segmented control much like the Bold/Italic/Underline control in TextEdit.
Is there a way to set a custom attributed string for each segment? [set attributedStringValue:] on the cell had no effect (there's no way to set per segment anyway).
If I have to resort to custom drawing, how can I reproduce the inset/blue highlight in the selected state?
Example:
I think these are all icons you need to pre-create and set in the segmented control. Custom drawing would be another option, but I think simply using 3 icons (plus their hires variants) is more flexible.
For custom drawing you'd use an NSAttributedString where you set font and color. Draw it twice, once in white with one pixel vertical offset and and once in blue/black.

NSWindow Content Border messing with CALayer's geometry

I have an NSWindow with a 32px bottom content border. Inside the window's view, I have two custom subviews. Each of them are layer backed, and I'm tracking the mouse with an NSTrackingArea. Part of what I'm doing is some mouseOver effects with CoreAnimation. This is not a problem in general, but I noticed something kind of strange and wondered if anyone knows why this is happening.
When setting up the trackingArea and mouseOver method, I hitTest the root layer and log the layer's name so I can see if the geometry of the various sublayers hold water when I resize the window. Internally, they seem (and look) fine. Visually, they are in the right place, but when I move the mouse, I notice that the though the mouse is physically over a layer, hitTest is returning whatever layer is 32 px above it. However, if I remove the content border, it works as you would expect and the correct layer is returned.
I obviously need the content border, so I have a very simple workaround which involves offsetting the hitTest point by 32px. This works fine, but it just seems weird that the presence of a content border seems to skewing the co-ordinate system of these subviews. Does anyone know why this could be happening?
NSEvent returns mouse locations relative to the window's coordinate system, not the targeted view's. You probably need to call convertRect:fromView: to get the correct coordinates.

Cocoa: Custom control not limited to window frame - how to start?

I want to build a custom control that would work like this:
You have a kind of NSButton with an image.
You click the button and than appears a big square with a grid of photos.
You click one of the photos and it is set up as new image for the button. (square dissapears)
Now, how to draw this big square with photos if I want it not to be limited to window frame?
I mean, if the button was close to window border the square is going to be partially outside window. I would also like to add some shadow to the square and an animation for opening/closing.
One important thing: I want to be able to draw not only a square but any other simple shape (circle)!
This isn't really a drawing question so much as a general custom views question. It's important to make that distinction.
I'll describe this in terms of rectangles to give you the general idea*. You should make sure you understand the view hierarchy and view geometry in Cocoa. Without this important requisite knowledge, you'll remain dead in the water.
It's easy to set an NSButton's image, so I'll leave that to you. Your button's action, however, would tell some controller to show the "image picker" for the given button. Your image picker would be some type of borderless window with an image list inside. The image picker could be an IKImageBrowserView (you'll have to enable Image Kit in Interface Builder for this control to appear), which gives you an iPhoto-like grid of images (with/without titles, different border types, etc.).
An explanation of the operation of this controller and how it creates the window, manages the selection, and sets the button's image is very broad so if you get hung up on any of those steps, you'll need to create a separate question for each problem, otherwise this answer would have to be an instruction manual for writing your app for you.
* Your problem is a little more difficult because of your desire to have differently-shaped "popup windows" ... you'd have to make sure your available photos fit neatly within the shape so none of them are cut off. Armed with the basic knowledge of view geometry, I'll leave this to you as an exercise. A hint: you can use a borderless, transparent window to host a view that draws itself in any shape you please.

Resources