How can I get the outline of a UIView - ios

Is it possible to get the outline of an UIView as a CGPath? I've taken a look over the UIView and CALayer methods but I couldn't find anything useful.
Edit
Consider the image below. I want the CGPath that follows the border (assuming that outside the border the view is transparent). This is just an example, I need something that would work with any shapes.

A UIView (or NSView in Mac) is a rectangular area by definition. What you see in your Show Notification example is the result of drawing into that view.

Related

Animating an image over another image in iOS

So basically i have two image objects, 1 portrays a line and the other a circle. I wanted to know if its possible using something like CABasicAnimation to loop the line image across the x axis but still keeping it within the circle image?
Yes, you should be able to do this with either CABasicAnimation or UIView animation.
CAAnimations only operate on CALayers, and they are rather tricky to use. I suggest using UIView animations on UIImageViews or other UIViews instead. You could even set up a custom subclass of UIView to have a CAShapeLayer as it's backing layer and then animate the custom UIView using UIVIew animations

Making a `UIView` line go half rounded on center of itself

I'm struggling with a problem:
I did create an UIView with subviews inside to make my own UIToolBar.
I added a UIView which acts like a delimiter line on top of it.
Then I decided to make one of the subviews rounded on center. But I need to find a way to "curve" the delimiter UIView.
Actually I have:
I want:
Is there anyway to fullfill my goal programmaticaly in swift ?
I thought about importing an UIImageView and make the images according to the differents iPhone size but is there any other solution ?
I solved a similar problem by sandwiching a dark gray circle image behind the toolbar, and a light gray circle image in front of the toolbar but behind the button. It's a hack but it works perfectly if you match the colors, and it's easier than doing path drawing.

CAShapeLayer not tapable when above UIScrollView

I have a UIScrollView that has a circular shape and inside it there is a image placed on the screen and above the UIScrollView shape to the right side of it.
I also have a CAShapeLayer that has a circular shape too that is overlapping a little, becouse i want it to look like that.
The problem is my touchesBegan cant detect tap in the overlapping area of the CAShapeLayer.
I want to be able to scroll the image inside UIScrollView while be able to tap the whole area of the CAShapeLayer object with objective c.
Please help me and show me how... i don't know how to do it.. have searched in 4 days.. but i can't find a way.

Swift xcode horizontal line

I wonder what the best way to create a horizontal line is?
I have a few labels / text and I would like to add a horizontal line between them. More or less like a when using twitter bootstrap.
Right now I am using a UIview and setting it as 1 in height with a black background color. But I guess this isnt the best way to do it?
That is the way to do it in iOS. UIView is the class which represent something to be shown on the screen. Every UI component is direct or indirect descendant of UIView. So, you should use UIView.
UIView is backed by CALayer to render the content to screen. You could also use CALayer, CAShapeLayer or other layer classes to create a border. But, I would not recommend to use CALayer just to show a border as it is simpler to use UIView with height of 1, on the top of that, you get some nice addition such as autolayout. If you use CALayer, you will have to set frame to layer at appropriate time when the view bounds change. It could also be tricky due to some intrinsic animation within CALayer.

UIView animation in drawrect

I need to continuously change the color of all the lines I draw in a UIView. And I drew all the lines within the drawrect method to assign colors. Now I need to animation and change the colors as long as the view is shown. Is there a way to do it? Thanks a lot!
Look into using one instance of CAShapeLayer for each of the lines, instead of drawing them in drawRect:. You can animate changes to each layer's path and strokeColor properties as necessary.
EDIT
If you're just drawing horizontal lines, you may be better off simply using a UIView for each. Set the backgroundColor instead of implementing drawRect:. You can animate both the frame property and the backgroundColor property using +[UIView animateWithDuration:animations:] (or the more powerful variants of it). This is generally simpler than messing around with Core Animation.
Live and learn. Animations are better done outside of -drawRect:
Change your "lines" to individual UIView instances added as (preferably opaque) subviews to your view. You'd then set the appropriate backgroundColor on the view.
You can then use a simple UIView animation to animate them.

Resources