Best way to draw border on UIImageView

Discussion in 'iOS Programming' started by jschulbach, Jul 15, 2010.

  1. jschulbach macrumors newbie

    Jun 29, 2010
    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?
  2. jschulbach thread starter macrumors newbie

    Jun 29, 2010
    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.
  3. PBG4 Dude macrumors 68020

    PBG4 Dude

    Jul 6, 2007
    That's a neat and easy solution! I would've been bordering my images instead of this simple idea. :) Thanks for posting.
  4. kainjow Moderator emeritus


    Jun 15, 2000
    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.

Share This Page