how to set a background image as colorWithPatternImage in swift

后端 未结 7 627
心在旅途
心在旅途 2020-12-23 11:10

My questions is, is it possible to have a UIView display an image, and if so, how so I do it? All I can find is the colorwithpatternImage which no longer works

7条回答
  •  囚心锁ツ
    2020-12-23 11:49

    This took me quite a bit of effort, capturing and passing along for reference. See below for full example of generation and use with swift.

    Reference Example

    • GitHub(jmr): Texture Reference - '0_1_TextureRef'

    Demo App

    Code Excerpt

    Here is how a UIView is textured in the demo, see code for full listing -

    func genTexturedView(_ view:UIView) {
        ...
        image.image = UIImage(named:"purple_example");
        view.addSubview(image);
    
        print("ViewController.genTexturedView():    Textured View added");
    
        return;
    }
    

提交回复
热议问题