How does an imageView appears in layers? - ios

example
I'm looking for help developing a UIImageView that appears like the imageviews in photo. It will include several images. I want it to be appears in layers.

I think you're best off making a custom class (UIView) which accepts a few images. Then in that custom class, draw those images in UIImageView. Every time you're drawing that image make sure you're rotating the UIImageView a few degrees using transform. You could do something with a white border, too. This will intensify the 'polaroid photo' effect.

Related

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.

Detect touch on irregular shaped images that are closely placed inside a UIView

I have situation where large number of images are placed closed to one another inside a view, each image has its own image-view. The images are high resolution pngs and are irregular shape such as shape of a country. The problem is that I wish to do something uniquely when an image is touched. However, the frames of image-views are all rectangles and overlap neighboring images and hence correct detection is not possible.
I would really appreciate any guidance in this regard. Please let me know if I have not clearly explained my problem.
Regards
Check this question (Detect touches only on non-transparent pixels of UIImageView, efficiently)
On github, you can find a project by Ole Begemann which extends UIButton so that it only detects touches where the button's image is not transparent.
Since UIButton is a subclass of UIView, adapting it to UIImageView should be straightforward.
Hope this helps.

UIimageview fit to round shape

I have an UIImageview that contains a circle (The obstacle) and then another UIImageview that contains another image (my character). When my circle hits my character the game ends.
My problem occurs when the game ends on the character touching the UIImageview box that my circle is within, rather than the circle inside the UIImageview box.
The solutions I can think of are:
Make the UIImageview rounded to fit my circle.
Somehow detect a collision between my characters pixels and the circles pixels rather than the UIImageviews.
Help and ideas would be really appreciated. I am a beginner with xcode.
Thanks!
Couple of different techniques:
1)UIView#layer.cornerRadius - Super simple to implement, just set that one property. But really bad for scrolling elements like table views.
2)UIImageView as a mask - Also easy to implement. Basically make a square image with a transparent circle in the middle and slap it on top of your view with a new UIImageView. If your circle design has some reflections or styling, this might make your life easier.
3)Custom drawing - Make a UIView subclass and override drawRect to draw your image and clip it to a circular path.
Hope that helps!
EDIT:
You can read this answers.
1)Fill an UIBezierPath with a UIImage
2)iOS: Inverse UIBezierPath (bezierPathWithOvalInRect)
3)How to mask a square image into an image with round corners in the iPhone SDK?

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

How to use a UIView with a CCLayer cocos2d?

I am playing a short video with CCVideoPlayer in cocos2d and at the end of it I am capturing the very last frame of the video and I am showing it on the screen using a UIView because trying to draw it on a CCLayer makes the image show up with slightly different colors. I would imagine that is because the way that things are drawn in cocos2d is different than the way they are drawn on a UIView. So I need some way to keep the image on the screen Using the UIView, and I need to be able to draw sprites etc... on top of this view. So my question is, Is there a way to make a CCLayer transparent so that the UIView containing the image can still be seen and then draw on top of the image using a CCLayer?
(P.S I am using cocos2d v1.1.0-beta2b)

Resources