'self.image.frame.width = 20 give get only property error

i tried to change the width of my Image view to 20 @IBOutlet weak var image: UIImageView! using this code in viewDidLoad self.image.frame.width = 20 but it give me error cannot assign to property: width is a get only property. what does that mean?? sorry i am new to swift i do not know what it mean.please help



Solution 1:[1]

get-only means you can only read this property (for example to compare with something), but not change. To set width you need this:

self.image.frame.size.width = foo

Solution 2:[2]

There is 2 ways to solve this:

  1. self.image.frame.size.width = some value

  2. You can add width constraint to your view (by code, storyboard or xib) and set this constraint's constant property to some value

Solution 3:[3]

Swift:

let widthValue = self.view.frame.size.width
self.btnName.frame.size.width = widthValue
self.txtEMail.frame.size.width = (widthValue - 32)
self.lblUserName.frame.size.width = (widthValue * 2)

Solution 4:[4]

self.image.frame.size.width = 200

self.UIView.frame.width is read only property

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JuicyFruit
Solution 2 nicat mahirson
Solution 3 Deepak Tagadiya
Solution 4 iamjpsharma