calayer
Rotating a CALayer 90 degrees?
Obj-C: theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * M_PI, 0.0, 0.0, 1.0); Swift: theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * .pi, 0.0, 0.0, 1.0) That is, transform the layer such that it is rotated by 90 degrees (π / 2 radians), with 100% of that rotation taking place around the z-axis.
UIButton with GradientLayer obscures image and darkens gradient
So I managed to get around this by doing a [button bringSubviewToFront:button.imageView] after adding the gradient. Seems that no matter what I do the new layer will add on top of the imageView, so I need to push that to the front afterwards. Objective-C: [button bringSubviewToFront:button.imageView] Swift 4.1: button.bringSubview(toFront:button.imageView!)
Tagging CALayers in iPhone
You can also use the name property of the CALayer. [layer setName:@”myKey”]; To look it up, – (CALayer *)myLayer { for (CALayer *layer in [superLayerOfMyLayer sublayers]) { if ([[layer name] isEqualToString:LabelLayerName]) { return layer; } } return nil; }
Animate CALayer border change
Both borderColor and borderWidth are animatable properties but since you are doing this in a view subclass outside of an UIView animation block, implicit animations (those that happen automatically when you change a value) are disabled. If you want to animate these properties then you can do an explicit animation with a CABasicAnimation. Since you … Read more
Drop a shadow to right and bottom of uiview
Try the following code, it might help you myView.layer.shadowColor = [UIColor purpleColor].CGColor; myView.layer.shadowOffset = CGSizeMake(5, 5); myView.layer.shadowOpacity = 1; myView.layer.shadowRadius = 1.0; myView.layer.maskToBounds = NO; I tested this code and it’s working and output is:
Using CALayer Delegate
Preferring to keep the layer delegate methods in my UIView subclass, I use a basic re-delegating delegate class. This class can be reused without customization, avoiding the need to subclass CALayer or create a separate delegate class just for layer drawing. @interface LayerDelegate : NSObject – (id)initWithView:(UIView *)view; @end with this implementation: @interface LayerDelegate () … Read more