I have custom UIView where there's lot of sublayers, I want to store UIView in NSArray and reload it to screen later. Is there anyway I could do that? Please help... Thanks!
Update:
I have UIView, that UIView has a root CALayer with lots of sublayers, what I want to do is to store that UIView along with it's CALayer's sublayers, so that when I want to access that UIView I'd still be able to see the same (just exactly how I stored/saved it).
Related
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
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.
So what I need to do is skewed UIViews (UIImageView, UIButton etc..).
I figured I need CAShapeLayer with CGPath. So far so good. Then I need to assign this to myView.layer.mask. Its ok too. But what if my UIView resizes? Do I need to recalc/remake the mask or is there some place I can put this to occur automatically?
I can't KVO with Categories (Objc) or extensions (Swift) since I can't globally modify dealloc method.
So I created a Swift subclass of UIView that will do the layer masking with didSet observer on bounds. It servers as container for subview/s that are supposed to be skewed.
I have a UIButton. Rather than giving it a background Image, I want to use a custom UIView object as the background. I realize I could do this by rendering the UIView into an image, then using that. But is there a better way?
I've looked at playing with the Button's view tree, but that seems to have undesirable side effects.
To achieve the same, I usually do this:
Add subview to the parentView
Add a UIButton with clearColor to the parentView, with the same frame as the subview.
You can achieve the same by creating a custom UIView class that has this view and button as its properties.
If you want to use a UIView as a button, you should just add a tap gesture recognizer to the UIView and use that. Is there something specific you're looking for?
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.