ios-uiview-Setting background Image 4 ways

Source: Internet
Author: User

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 UIView4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.