Round corners in UIView: CALayer or background Image? - ios

I need to make a UIView with rounded corners like this() in tableView with a very large number of items. Therefore, my question is whether the CALayer bad influence on smooth scrolling, and may be better to use for the background image for this case?
Thanks.

CALayer is fine. Transparency is bad for performance though.

Related

How can I animate a tile in a UIView

I need to create an animated chevron effect using the bitmap tile below. I am hoping that a UIView with a pattern fill will be sufficient, but I need to be able to animate the origin of the pattern over time, and I can't see that this is possible.
I think this is possible with Quartz, or CoreGraphics at the low level. What would be the best way to do this, and can you provide some example code in Swift that demonstrates the solution?
I would add the image as contents of multiple sublayers (CALayer instances) aligned one below the other and animate those sublayers y position.
The main layer would clip its sublayers on the border and sublayers that go offscreen would move to the bottom to be reused, similarly to how UITableView reuses its cells.
You might also want to look at CADisplayLink to have better control of the rendering.

How to make view's board like tear from the paper?

I want to make the view's board like tear from the paper(in the picture) by code ,but I don't have any idea.Please help me!
You can do something like this a UIView using CALayer’s mask property for the torn edges, and using a UIBezierPath with CALayer’s shadowPath for the shadow.
Drawing something like this with shadows and transparency will be relatively slow. Of course the other (and perhaps easier) approach would be to use a static background image created in Photoshop or something similar.
See here for details on drawing using BezierPaths
Drawing on Transparency layers

iOS7 "Slide to unlock" animation on a UILabel

How to make an animation similar to "Slide to unlock" text on a UILabel? (The text gradient is animated left->right) and then the text color adapts to the background.
I think the key to performing this effect is CALayer mask. You can attach a second CALayer to any existing layer as its mask. Then:
The [mask] layer’s alpha channel determines how much of the [parent] layer’s content
and background shows through. Fully or partially opaque pixels allow
the underlying content to show through but fully transparent pixels
block that content.
So the text is going to be the mask and the moving colour is going to be the parent.
The easiest way to deal with the text will be to use a CATextLayer. The easiest way to make the colour gradient will be CAGradientLayer.
To animate the gradient you can use Core Animation, since all properties are animatable. I guess locations is likely to be the best way to achieve the sliding animation.
For convenience you'll probably want to wrap all of that up into a UIView, but you can add layers directly if you prefer.

CALayer: Maintaining cornerRadius on layer's contents

I've been looking at the CALayer's documentation and it seems like cornerRadius only affects the background of the layer and not the contents.
Is there a way to apply the corner radius to the entire CALayer without taking a big performance hit?
I've seen suggestions about masks, but that sounds costly. I've also seen suggestions about drawing the contents manually, but I don't really know where to start. I know a bit about rendering images in contexts, but I don't know how I'm supposed to draw it onto the CALayer's content view with a corner radius. The best I would know is to subclass CALayer and override the drawInContext method and use CGContextDrawImage.
All help is greatly appreciated, but to reiterate the question: "Is there a way to apply the corner radius to the entire CALayer without taking a big performance hit?"
cornerRadius does apply to the entire CALayer and it does not cause a big performance hit. If you are not seeing the contents with rounded corners, it is because you have forgotten to set masksToBounds to YES.

UILabel with cornerRadius inside UITableView

i'm trying to immitate the count-label that is used in apples mail app, which shows the count of messages in a folder / mailbox. The text color is white, and the labels background is gray/blueish with rounded corners. (screenshot)
To get the same look, i made a custom UITableViewCell for my table, and tried to style the corresponding label like this:
label.layer.cornerRadius = 10.0;
This code basically looks like the mail app. However the performance of this code seems to be really poor. i've installed the app on my iphone 3gs, and when scrolling the table, the view is moving really slow and unsmooth. when i disable the rounded corners, its running great again.
is my code somewhat wrong, or what can i do to improve performance? should i use png backgrounds rather than rounded corners? if so, what would i need to do to have the png background adjust its width according to the label width/text length? i already added code to do this and it works, but i think for png backgrounds it would just strech/distort the background image, right?
It sounds like using cornerRadius may force CALayer to do clipping, which is expensive. You can also "can" the shape as a stretchable image (which could be used as a background image on a UIView descendant) or draw it using CGPaths or UIBezierPaths.
the simplest way is you make a bakground image and use it this is simple siloution and if you want to by coding then it is difficult because UIlabel is not have redious corner

Resources