views:

251

answers:

1

Hi all,

I have a modal view in my iPhone app (Xcode, Objective C++). How do I make it look as pretty as the system UIAlertView? Specifically, I want:

  • rounded-rect window with a border around it
  • semitransparent background
  • subtle highlight near the top

The transparency can be probably achieved with a less than one alpha channel on the background color. What about the frame and the rest?

+5  A: 

On iPhone OS 3.0 and later, you can get the rounded corners easily by setting the borderRadius property of the view's layer.

view.layer.cornerRadius = 5;

You will need to #import <QuartzCore/QuartzCore.h> to get the headers for the CALayer class.

You are right about the transparency, just use a color with an alpha component, and make sure that the view is not marked as opaque.

As for a highlight, you could either do it programmatically or using an image.

If doing it programmatically, you will have to use Core Graphics and do some drawing with CGGradient.

If using an image, take a look at UIImage's stretchableImageWithTopCapHeight:leftCapWidth:; you can resize an image without distorting the corners.

benzado
Surely you meant `cornerRadius` - there's no such thing as `borderRadius` on `CALayer`.
Adam Woś
Oops, fixed! I must have been thinking of the CSS property.
benzado