Is it possible to overlay UIView
with an image without using UIImageView
from the Interface Builder?
If not, how would you accomplish the same in code?
From the UIView documentation:
Image-based backgrounds - For views that display relatively static content, consider using a UIImageView object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic UIView object and assign your image as the content of the view’s CALayer object.
Using the second option, to set someView to have a background of yourImage.png:
someView.layer.contents = (id)[[UIImage imageNamed:@"yourImage.png"] CGImage];
if by Overlying a UIView you mean painting its background with an image, it can be done like this:
someView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImage.png"]];
You could also add a new UIImageView that covers your UIView by code, Init your UIImageView with the same frame Rect as your UIView and add it as a subview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With