Flying_Banana
Flying_Banana

Reputation: 2910

Adding a border and shadow to a nib initiated view

I am making a subclass of UIViewController which, when the user pressed a button, will initiate and add a view from another UIViewController subclass.

Inside the added view I have an instance of UIWebView and UIButton (for closing the popup).

Since it is intended as a pop up, I want to add a border and a shadow to the UIWebView, but since it is nib initiated, I don't know how I can modify the drawing code.

Any help? :)

Upvotes: 0

Views: 695

Answers (2)

Piyush Dubey
Piyush Dubey

Reputation: 2414

You can add Border and Shadow to any control in this way.
You can also set Width of Border and can also make it Rounded.

CALayer * l1 = [viewPopup layer];
[l1 setMasksToBounds:YES];
[l1 setCornerRadius:5.0];

// Add a border
[l1 setBorderWidth:5.0];
[l1 setBorderColor:[[UIColor darkGrayColor] CGColor]];

// Add a shadow
[l1 setShadowColor:[[UIColor darkGrayColor] CGColor]];
[l1 setShadowOpacity:5.0];
// You can more methods for shadow

Just replace viewPopup with your control.

Note:- Don't forget to import <QuartzCore/QuartzCore.h>

Upvotes: 0

bobnoble
bobnoble

Reputation: 5824

Take a look at using the view's CALayer.

To add a border:

myView.layer.borderWidth = 1.f;
myView.layer.borderColor = [UIColor blackColor].CGColor;

There are similar methods for adding a shadow:

myView.layer.shadowColor = [UIColor blackColor].CGColor;
myView.layer.shadowOffset = CGSizeMake(4.f, 4.f);
myView.layer.shadowRadius = 4.f;
myView.layer.shadowOpacity = 0.5f;
myView.layer.shouldRasterize = YES;

You will need to add the Quartz framework to your target, and import the header in your controller's .m file:

#import <QuartzCore/QuartzCore.h>

Upvotes: 1

Related Questions