One. Set the background image for UIView
1. Use the image as the background color of the UIView, which takes up too much memory and is not recommended. 1.imageNamed mode
Self.view.backgroundColor = [uicolorcolorwithpatternimage:[uiimageimagenamed:@ "Image.jpg"];
2. Mode NSString *path = [[nsbundlemainbundle]pathforresource:@ "image" oftype:@ "jpg"]; Self.view.backgroundColor = [Uicolorcolorwithpatternimage:[uiimageimagewithcontentsoffile:path]]; Both of these methods consume a lot of memory when generating color. If the picture is not large enough, it will tile more than one image, not stretching it to fit the view size. After the view is released, the color in 1 does not follow the release, but is always in memory, and the color in 2 is then released and, of course, the memory is applied again when the color is generated again
2. Add a uiimageview display image on UIView as a background image of UIViewNote: If there is a click event, the userinteractionenabled user interaction is set to Yes. The
3.iOS view is a layer, the first placed layer will be at the bottom, so the first to add a uiimageview to UIView can be used as a background image of UIView。
4. Other methods (recommended)NSString *path = [[nsbundlemainbundle]pathforresource:@ "image" oftype:@ "jpg"]; UIImage *image = [Uiimageimagewithcontentsoffile:path]; Self.view.layer.contents = (ID) image. Cgimage; Note: To write a clear suffix, even ". png".
ios-uiview-Setting background Image 4 ways