Colorable pin view - ios

Does anyone know of any code to draw the pins we see in MKPinAnnotationView in a regular UIView?
The motivation is to remove the hundreds of different colored pin images we are currently bundling with our app to drop all over medical images (regular UIView backed - not MKMapView). All I really need is to alter the pin color programmatically .
NB: I am not talking about the callout as seen in SMCalloutView etc .
This is to be used outside MKMapView. They are dropped into a normal UIView.

Here are two approaches to consider:
Ship a single pin image - say, red. Use the Core Image CIHueAdjust filter to change it to other colors.
Ship a pin image with a white bulb, and an alpha-channel-only mask image that selects the pixels in the bulb. Use Core Graphics to create new pin images dynamically at runtime. You'll want to draw the white bulb pin into a bitmap context. Then use the mask image to set the context's clipping mask. Finally, fill the context with whatever color you want the bulb to be.

Related

Overlay MapView with hole

I would to add an overlay on mapView with a hole.
So, I would add a black transparent overlay on my map and on a specific position I would to have this hole through which I can see the map without black overlay.
In this hole I have to show my results. Is possible this?
(1)If the overlay could be a simple imageview. Just prepare a png file with full transparent hole and black transparent background.
(2)If you need a dynamic view which might be different at run time, I think the best approach is to prepare a similar image from (1), then apply it as layer mask.
Here is a tuto:https://www.youtube.com/watch?v=H6V_PbCKEO8

How to create a non-rectangular UIImageView

I'm trying to make a ViewController that presents info from a webpage like this:
However, I'm confused on one thing. How did they get the imageView to display an image that's cut off at the corner, i.e. not rectangular? Do you think they created that player card in Photoshop and used it as the background for the imageView image, or did they create it programmatically?
I wonder because the image is behind the picture of the bear, so I imagine if they created the background in Photoshop, how would they get the image behind the bear head? They can't have just created the card with the player's picture as part of it, then loaded the whole image because if they traded the player, because I'm sure they pull the player info and picture from the web so they can have a card for all players, even if they trade or acquire a new player mid-season, without having to update the app (and add the finished image to images.xcassets).
This can be composed from two CALayers at runtime. Put the picture on the bottom layer; the picture can come from anywhere - the web, the bundle, etc. the image source could be dynamic.
Put another CALayer on top, with the frame rendered with opaque colors, and a transparent cut-out for the picture in the middle:
There are a bunch of ways to do this. A simple and flexible way to do it is to create a CAShapeLayer that's the same size as the image view, with it's origin at 0,0, and add it as the UIImageView's layer's mask.
You'd create a filled UIBezierPath that maps out the part of the image you want to show, and install the bezier path's CGPath into the mask layer's path property.
The result would be that the image view is cropped so that only the part inside the shape is drawn.

I want to draw custom shape like apple shape on UIView

I am trying to make Apple kind of shape for progressHUD. I have option to use .png Image but I cant because I have to fill the apple Shape with different colour depends of percentage status.. I am using UIView to draw this shape...
I want suggestion how to draw apple kind of shape easily?
And How we can fill half colour with different colour?
I have option to use .png Image but I cant
Yes, you can. — Get hold of some apple-shaped artwork. Use it as a mask - it punches a hole in a view. Now put another view behind it, with a color. Now the apple appears to be that color, because that color is being seen through the apple-shaped hole. Now put another view behind it, with a different color, and move it up or across the right amount so as to divide what's seen through the apple into two colors.
Using that approach, it took me about 30 seconds to create this result (using your apple-shaped artwork as a .png image!):

Setting the image of a UITableViewCell to a circle of a specific color

On my table view, I want to display small circles of certain colors that will provide context for the information. The circles should be in the location that the image would usually be in (the left hand side). Is there an easy way to do this? I was thinking that I could create a new image view and simply draw on it using some drawing routines. The problem is I don't know any of these drawing routines, or at least I don't know how to use them outside of a drawRect function.
Well, the easiest way would be to include the different images in your bundle and conditionally set them to the cell's imageView's image property in cellForRowAtIndexPath:.
However, if you're looking for alternative's you could subclass UITableViewCell, and use CAShapeLayers to draw them programmatically and add them to the cells layer in what ever position you want.
Here's an example of how to use CAShapeLayer to draw a circle:
iPhone Core Animation - Drawing a Circle

Apply a CIFilter to a UIView & all subviews

I have a UIView, that contains a UIImageView for its background. The view contains a number of segments (UIImageViews), which the user can drag and drop images to. I want to add a CIFilter to the whole view, such that any images that are subsequently dropped into the view will have the filter applied instantly. But the filter shouldn't be applied to the main view's background image. I realise that a CIFilter requires an input image, I was thinking of using a transparent input image, then placing the filter on top of all the views so it would only be visible when there is an image behind it.
Is it possible to supply a transparent input image to a CIFilter?
Is this the best way of going about it?
I suppose I'd need to mask the filter to the view containing the segments so that it is not applied to the background image. How would I go about this? Since a mask needs an image to mask to, I guess I'd need to render the segments view to an image and mask to this?
Thanks in advance

Resources