I want to add a rounded rectangle shape in iphone interface but the iphone library doesn't have that object. How do i do it?
Asked
Active
Viewed 2,033 times
0
-
[Search Stack Overflow.](http://stackoverflow.com/questions/1225383/rounded-uiview-with-shadow) – Alex Reynolds Dec 03 '09 at 07:36
3 Answers
3
You create an UIView subclass, in which you
#import <QuartzCore/QuartzCore.h>
and set its layer's cornerRadius
property in code to a certain amount:
self.layer.cornerRadius = 5;
self.clipsToBounds = YES;
If you like you could create a property of your object, say roundedCornerRadius
, and listen to its changes using KVO, in a code fragment similar to
[self addObserver: self forKeyPath:@"roundedCornerRadius" options:0 context:nil];
//implement in your UIView subclass
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqual: @"roundedCornerRadius"])
self.layer.cornerRadius = roundedCornerRadius;
}

luvieere
- 37,065
- 18
- 127
- 179
0
Create rounded rectangle image of your interest. you can add this image to different UI Controls.

Jim
- 4,639
- 5
- 27
- 31
0
luvieere's answer worked for me.
Created a UIView subclass to hold the subviews i need to round the corners of. (I used IB).
Set that view to be the view of a UIViewController.
Overloaded viewDidLoad in the view controller to call a custom "viewDidLoad" method in the custom view.
That's where I set the corner radius for the subviews that need rounded corners.

Jon
- 462
- 4
- 13