简体   繁体   中英

Rounded corners for images

I remember seeing the code before which takes a square image (link an iphone icon) and rounds the corners and adds the effects like apple does in iTunes. Basically I get the icon image from iTunes and want to make it look like it does in the store.

Can anyone point me in the direction?

You need to import the QuartzCore framework to implement the following:

Your iconView , (in this example) below should be a UIImageView :

[iconView.layer setMasksToBounds:YES];
[iconView.layer setCornerRadius:5.0];

/* setting the border is not necessary, but is an option for you. */
[iconView.layer setBorderWidth:0.0f];

to round the corners:

#import <QuartzCore/QuartzCore.h>
...
int r = 15;
AnyUIViewSubClass.layer.cornerRadius = r;

try these links:

https://stackoverflow.com/a/1850269/215494

https://stackoverflow.com/a/4687593/215494

https://stackoverflow.com/a/8334624/215494

that doesn't add the shine/gloss effect, but if your image size is fixed, you could add another NSImage of a semi-transparent gloss PNG/JPG on top of it, or you could do it entirely programmatically by drawing intersecting NSBezierPath s into NSImage and then compositing the result over your rounded-rect image. you could also compose the whole thing into one final NSImage .

Cocoa With Love has a very nice article about creating icons with gloss, shadows, gradients and all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM