How do set a width and height of an Image in Swift

后端 未结 4 1212
慢半拍i
慢半拍i 2020-12-08 04:46

New to Swift and iOS programming in general. I couldn\'t figure out how to set a width and height of an image.
For example,

  l         


        
4条回答
  •  鱼传尺愫
    2020-12-08 05:27

    My suggestion is.

    Instead of set size of image you should set size of UIImageView and then put this image on it so, size of image will be display as per your requirement.

    Such like,

    var imageView = UIImageView(frame: CGRectMake(100, 150, 150, 150)); // set as you want
    var image = UIImage(named: "myImage.png");
    imageView.image = image;
    self.view.addSubview(imageView);
    

提交回复
热议问题