A layer
's borderWidth
and borderColor
properties draw a border inside the view. Remykits pointed this out here.
A layer
's shadow...
properties cannot be used to create a border that both appears on all four sides and is opaque for reasons I showed here.
What I failed to specify in that question (and the reason I've opened a new one) is that I want the border to be outside the view. Increasing the frame
of the view to compensate for the space lost, as has been suggested, doesn't work; I'm using a UIImageView
, so even if the frame
is increased, the image
is still cropped.
Another suggestion was to change the contentMode
of the UIImageView
to .Center
, in combination with changing the size of the view, but this doesn't work as the view then isn't the proper size.
The solution I first thought of was to create another UIView
"behind" this UIImageView
, and give it a backgroundColor
to mimic the effect of a border. I also thought of creating a custom subclass of UImageView
. Both courses of action, however, involve making calculations based on the frame
of the view. I've had many problems with the frame
not being set by AutoLayout at the proper time, etc.
Other things that come to mind are digitally adding a border to the image or positioning the image in a specific part of the UIImageView
. (My attempt at the latter was imageView.layer.contentsRect = CGRectInset(imageView.bounds, 4, 4)
, which resulted in a strangely pixellated image.)
To be clear, what I'm looking for is this:
It really feels like there should be a simpler way to do this than creating a new class or view. Any help appreciated.