PDA

View Full Version : Best way to draw border on UIImageView




jschulbach
Jul 15, 2010, 04:00 PM
I've got a couple of UIImageViews that are square but contain either tall or wide images with aspect fill so they fill the square. If I wanted a border around these images what is an easy way to do that? I didn't see a border option for image views in IB so would I want to just put another image view behind them that is 1px larger in each direction? What is the best way to go about adding the border?



jschulbach
Jul 15, 2010, 04:53 PM
I think I found a good solution. I just used a view with the background color set to my border color, sized 1px larger than the UIImageView on each side. I was mostly concerned about efficiency and what method would affect performance the least but this method seems pretty simple.

PBG4 Dude
Jul 16, 2010, 09:53 AM
That's a neat and easy solution! I would've been bordering my images instead of this simple idea. :) Thanks for posting.

kainjow
Jul 16, 2010, 03:04 PM
You could try playing with the image view's layer which has a borderColor and borderWidth property, but that may not work on the UIImageView.