Creating an irregular UIButton in Swift where transparent parts are not tappable - ios

I am making a pie chart where each sector is a separate button with a background image, but UIButton has a rectangular shape and all the buttons overlap. Is there a way to make a UIButton the exact shape of an irregular image (in Swift) so this does not happen?
Any help would be appreciated

You can use UIBezierPath or CGPath to define your pie chart sections and use their containsPoint: or CGPathContainsPoint to detect touch

As I'm concerned, may be the CAShapeLayer is better way to achieve the pie chart. By doing that, you can use
[layer hitTest:]
method to deal with the touch action.

Related

How to set points of UIbutton like same shape like cashapelayer

I'm drawing chart and i want to add buttons on calayers.This red and blue color shapes are CAShaperlayer. i have used uibezier path to draw those layers.
Below is one of the good library to solve your problem.
You can download the source code from here.
Check into appetize.io

iOS: How to fill a rectangle except in one area?

I've used the CGContext based routine to fill a rectangle, but this time I actually want to fill all of a rectangle EXCEPT one part of it. I know this is possible in other drawing systems for other platofrm but can it be done with core graphics on iOS?
Both borderWidth and cornerRadius are animatable properties. So you could just animate them directly (using CABasicAnimation). In that rendering, you'd go from no border and no corners to having a border and corners in an animated way.
If you want to animate the rectangular tracing of the border, you'd need to use a CAShapeLayer (because the end of its path is animatable) and provide the illusion that way.

How to draw a dynamic circle in Objective-C

How to draw a dynamic circle in Objective-C
I have to draw 2 circles first outer circle radius is fixed shown in figure filled with green Color (A).
The other circle is dynamic based on some radius(B).
How can I achieve this.
Subclass an UIView and then override its drawRect method. Inside it use some NSBezierPaths and NSColor settings to make your drawings.
drawRect:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/drawRect:
Cocoa drawings
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40003290-CH201-SW1
Bezier paths
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html
Colors
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Color/Color.html#//apple_ref/doc/uid/TP40003290-CH205-BAJDFIFE
This might help you,
Download sketch from apple. http://developer.apple.com/library/mac/#samplecode/Sketch
see more
stackoverflow link

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

I have an UIImage that is a line drawn black & white image in a UIImageView. How can I fill inside of the lines with color on touch?

I have this UIImage in a UIImageView:
I want it so that when a user touches inside of any box, it fills with a blue color.
This is just an example... the actual image I am going to use is not squares, but a more complex line drawing, so drawing it with code would be extremely complex.
What is the best way to accomplish this?
You can go with flood fill Algorithm.
That is the best way to fill any image.
there is some links for that
http://en.wikipedia.org/wiki/Flood_fill
and get sample code from here
Flood Fill
Use UIView and implement its drawrect method to show the colors.Use QuartzCore and CoreGraphics to draw. Implement the touch with drawing of color to the view.

Resources