Add shading to clipped UIView - iphone

I'm creating an iphone application. I have this UIView whose content is clipped with a path. I want to add shading and/or shadow to it. What's the best way to do this? For shadow, I tried CGContextSetShadow() but it doesn't seem to have an effect (perhaps it's drawing outside the shown region?) . How about shading? I want it to appear along the path. What's the best way to go about it? Is it to create another narrow clip strip along the original clipping path (if it's possible to have two clip path... ) Or does this need to be done in another CALayer? I am not even sure what that is yet.

You can't add shadows to layers which are clipped or masked. The way I would do this is use two CALayers, one for the clipped content and place this inside another for the shadow which isn't clipped.

Related

Border around the image within an NSImageView

I have an NSImageView which contains an image. Is there a simple way to draw a border around just the image (which might be smaller than the NSImageView), and not the entire NSImageView?
[Answering my own question.]
On the off chance that someone comes cross this page looking to get something similar done, a simple way to do it is by using a wrapper view, and setting a border on the inner view.

How to change the shape of a UIButton in Swift?

I am trying to make an arrow shape. I understand that it will be done with CGRect method but can you give a complete example of how it will be done in SWIFT?
This can be done programmatically by first subclassing UIButton and overriding drawRect within it to form the shape of an arrow via bezier paths. Then simply set the title of the button to be whatever you want your text to be and position it accordingly within the shape you have drawn.
The benefit of doing it this way is that you can easily change the color of, scale and dimensions of the arrow since you control how the object is actually being drawn.
A good tool for drawing complex bezier paths is paintCode. I'm using the trial version and can pretty easily make shapes like this now.

How to draw custom line on MKMapview?

I've been searching for a way to draw a custom line, but the only help I can find is how to draw lines with an UIColor.
I want to draw a straight line but not just with a color. I want the appearance of the line to be customizable.
(So right now I can draw lines between 2 points, but not the line I want)
The line I want got straight 45 degree lines on it, and it's grey and black.
Anybody can help?
The line looks like this, I'm also thinking that I could stretch this image, but if I stretch it, it will look kinda weird.
Why don't you add image then? I'm new developer so I don't know other way to do it. Only OpenGL with texturing, but there is no need to use openGL. So my suggestion is to add image.
Sound like what your looking for is the MKPolylineView Class. You assign it a polyline which contains the points in your line. Since the polyline view is an MKOverlayPathView you can set the stroke and fill colors.
Since it's also a UIView subclass you can manipulate the appearance even further by grabing the views layer property and adding gradients, shadows, masks, etc.
Is there a specific effect that you're trying to achieve?

Can you set different CALayer border width on different side?

I am trying to create a pseudo-3D square (like a scrabble tile) and I was thinking of faking it with borders. But then I couldn't find a way to set different width for different side.
Is this possible at all? If not, does anyone have any recommendation on how to do this in CALayer?
Oh, one caveat, I am already using shadow, so can't use that to fake the bevel.
Not possible with ordinary CALayer properties. You'd have to inset your layer and draw the different borders in the drawing method, or add a second larger layer to take care of that inside its drawing.
You could possibly do it with the layer's shadow properties, using -shadowOffset to only render it on two sides. However, to make it really nice you probably have to draw it yourself.

Changing color of part of an image

I have a png image file that is partly opaque and partly transparent. I display it in a UIImageView as a mask of sorts over another UIImageView layered behind it (as a sibling subview of a common superview). It gives me perfect borders around something painted using a finger on the lower UIImageView in my stack of UIImageViews. Perhaps there are better ways to do this, but I am new-ish, and this is the best way I came up with thus far. None the less, my app is in the App Store and now I want to enhance it to provide more images to use as the mask of sorts over the finger painting. But I don't want to bloat my bundle size by adding more static mask images as I did for the initial implementation. Not to mention I don't want to spend lots of time in photoshop making 100 masks. I'd rather programmatically change the color of the mask, without affecting the clear portion in the middle, which is not a simple regtangle or circle, but rather a complex shape. So my question is this: How can I change the colored portion of my loaded image without affecting the clear color portion in the middle? Is there a reasonably easy way to do this? Essentially I want to do what is described in this post (How would I tint an image programmatically on the iPhone?) without affecting the clear portion of my image. Thanks for any insights.
Have a look at the Tinted Image sample project. Try out the different modes until you get the effect you want.