1

Here is the code:

  class ViewController: UIViewController {

 @IBOutlet weak var border: UIImageView!


  override func viewDidLoad() {
    super.viewDidLoad()


    let width = UIScreen.mainScreen().bounds.width

    let height = UIScreen.mainScreen().bounds.height


    border.image?.size.width = width
    border.image?.size.height = height
    }

but I got an error that says:

cannot assign to property: size is a get only property

Suhaib
  • 2,031
  • 3
  • 24
  • 36

2 Answers2

5

You cannot change the size of UIImage object this way. But you can change the size of UIImageView object.

so your code should be:

border.frame?.size.width = width
border.frame?.size.height = height

Then set your UIImageView's contentMode appropriately if you want it to fill scale/aspect fit etc.

If you want to change the UIImage object's size, then you need to redraw it using CoreGraphics.

GeneCode
  • 7,545
  • 8
  • 50
  • 85
1

In this case, I would suggest that you change the size of the imageview. Changing the size of image IS possible but in almost all cases changing the imageview size is the way to go.

DevKyle
  • 1,091
  • 6
  • 22