Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-15-2011, 05:35 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 3
jomonkc is on a distinguished road
Default iPhone UIView layer shadow effect

Hi all,

I am trying create a UIView similar to the following url image.

ImageShack® - Online Photo and Video Hosting

Its a UIView containing a UIImageview and label. Is there any way to create a uiview with shadow like this?

Thanks in advance,
Joe

Last edited by jomonkc; 06-15-2011 at 06:45 AM.
jomonkc is offline   Reply With Quote
Old 06-15-2011, 06:14 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

attachments doesn't work, use imageshack...
__________________
dany_dev is offline   Reply With Quote
Old 06-15-2011, 06:55 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 3
jomonkc is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
attachments doesn't work, use imageshack...
Hi,

This is the imageshack url of the image

ImageShack® - Online Photo and Video Hosting

Thanks
jomonkc is offline   Reply With Quote
Old 06-15-2011, 07:02 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

mmm......if you mean the bottom shadow, is not so easy, you should start looking this tutorial....
CodePadawan: iPhone Glossy Buttons

This allow you to create a "rounder shadow" intersecting a circle with a rectangle..
__________________
dany_dev is offline   Reply With Quote
Old 06-15-2011, 07:16 AM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jomonkc View Post
Hi all,

I am trying create a UIView similar to the following url image.

ImageShack® - Online Photo and Video Hosting

Its a UIView containing a UIImageview and label. Is there any way to create a uiview with shadow like this?

Thanks in advance,
Joe

I don't believe iOS supports shadows. They are too CPU-intensive. You could render the image beforehand in an image editor, and use it as a static image. If you save it as a png with an alpha channel, you can even get the shadow to draw over the background.

Bear in mind that semi-transparent content really bogs down iOS devices though. That's why iOS doesn't support shadows in the first place. The graphics hardware isn't fast enough to render shadows without lagging.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 06-15-2011, 07:40 AM   #6 (permalink)
Token farm animal
 
sneaky's Avatar
 
Join Date: Apr 2011
Posts: 321
sneaky is on a distinguished road
Default

Sure you can do shadows. This code here will create a view with a drop shadow. It won't do the curl effect you're after but I'm sure it can be tweaked.

Code:
    UIView *firstLayer = [[UIView alloc] initWithFrame:CGRectMake(100, 150, 100, 100)]; 
    firstLayer.alpha = 0.95;
    firstLayer.layer.cornerRadius = 10;
    firstLayer.layer.borderColor = [UIColor blackColor].CGColor;
    firstLayer.layer.borderWidth = 1;
    firstLayer.layer.shadowColor = [UIColor blackColor].CGColor;
    firstLayer.layer.shadowOpacity = 1.0;
    firstLayer.layer.shadowRadius = 10.0;
    firstLayer.layer.shadowOffset = CGSizeMake(0, 4);
    firstLayer.layer.shouldRasterize = YES;
    [self.view addSubview:firstLayer];
    [firstLayer release];
You can create just any shape with a background of clearColor and them apply the drop shadow effect to it. You can remove the border stuff.

Don't forget to import QuartzCore!
sneaky is offline   Reply With Quote
Old 06-15-2011, 08:45 AM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sneaky View Post
Sure you can do shadows. This code here will create a view with a drop shadow. It won't do the curl effect you're after but I'm sure it can be tweaked.

Code:
    UIView *firstLayer = [[UIView alloc] initWithFrame:CGRectMake(100, 150, 100, 100)]; 
    firstLayer.alpha = 0.95;
    firstLayer.layer.cornerRadius = 10;
    firstLayer.layer.borderColor = [UIColor blackColor].CGColor;
    firstLayer.layer.borderWidth = 1;
    firstLayer.layer.shadowColor = [UIColor blackColor].CGColor;
    firstLayer.layer.shadowOpacity = 1.0;
    firstLayer.layer.shadowRadius = 10.0;
    firstLayer.layer.shadowOffset = CGSizeMake(0, 4);
    firstLayer.layer.shouldRasterize = YES;
    [self.view addSubview:firstLayer];
    [firstLayer release];
You can create just any shape with a background of clearColor and them apply the drop shadow effect to it. You can remove the border stuff.

Don't forget to import QuartzCore!


Oops, you're right. My bad. Shadows were added in iOS 3.2. The last time I tried to use them, it was for an app that had iOS 3.0 as the minimum supported iOS, so I couldn't use them.

It doesn't help that the Zarra/Long Core Animation book I'm reading explicitly says that shadows are not supported. I guess it's based on the 3.0 APIs. That's actually more than a little frustrating. I wish authors would explicitly state the OS version their books are based on. iOS is changing so fast that the odds are, by the time you publish a book, the APIs you are documented have been updated. I looked pretty hard in the Zarra/Long book, and I could not find the version of iOS it was written for anywhere.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 06-16-2011, 02:19 AM   #8 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 3
jomonkc is on a distinguished road
Default

Thank you for all your quick responses. I fixed my problem. I created an UIBezierPath and assign to firstLayer.layer.shadowPath

Thanks you,
Joe
jomonkc is offline   Reply With Quote
Reply

Bookmarks

Tags
ipad, iphone, uiview, uiview animation

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 312
6 members and 306 guests
chemistry, Dnnake, iOS.Lover, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0