small medium large xlarge

Generic-user-small
21 Nov 2009, 02:56
Joe D'Andrea (3 posts)

Bill (if you’re reading this - hello! [waves])

In another thread, you wrote:

bq. “Generally speaking its bad news to mess with layers that are under the direct control of a view (such as a UIImageView’s layer …). Instead get the CGImage from the UIImage and make that the contents of your layer.”

Just to be sure I understand … I have a UIImageView (with an image, natch) and I’d like to give it rounded corners and a border without altering the original image. Sometimes it’s inside a scroll view, and other times it’s part of a table view cell.

Is the following ill-advised as a technique to accomplish this in short order? (If so, is there a better way that is just as thrifty?)

  CALayer *l = [myUIImageView layer];
  l.masksToBounds = YES;
  l.cornerRadius = 10.0;
  l.borderWidth = 1.0;
  l.borderColor = [[UIColor darkGrayColor] CGColor];
Generic-user-small
21 Nov 2009, 03:04
Joe D'Andrea (3 posts)

Addendum: Lest you think I’m a bit dense, I’m not sure if getting the CGImage from the UIImage is what I’d actually need to do here … but feel free to disabuse me of that notion!

Generic-user-small
21 Nov 2009, 03:28
Joe D'Andrea (3 posts)

OK, I ended up cheating. Sorta kinda. :)

Using Joe Hewitt’s Three20 library, this ends up a snap. (So, hmm, I started off with something CA-related and it ended up a bit different. Still, I hope someone finds this useful anyway!)

myUIImageView.backgroundColor = [UIColor clearColor];
myUIImageView.style = [TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:10.0] next:[TTContentStyle styleWithNext:nil]];
Biopic_100x100_pragsmall
21 Nov 2009, 17:33
Bill Dudney (917 posts)

Hi Joe,

I am reading (waves back)…

What you propose in the first post is spot on. RE:your question in the second post, you are correct that getting the CGImage from the UIImage is the right thing to do.

If the TTShapeStyle is working for you, perfect!

Good luck and let us know when you ship!

You must be logged in to comment