Overlaying UIView with Background Image

Is it possible to overlay UIViewan image without using the UIImageViewinterface builder?

If not, how would you do this in code?

+5
source share
2 answers

if, having exceeded UIView, you mean to draw its background with an image, this can be done as follows:

someView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImage.png"]];

You can also add a new UIImageView that spans your UIView by code, Initiate your UIImageView with the same Rect frame as your UIView, and add it as a preview.

+3
source

In the UIView documentation:

. , , UIImageView . , UIView CALayer .

, someView, yourImage.png:

someView.layer.contents = (id)[[UIImage imageNamed:@"yourImage.png"] CGImage];

+5

All Articles