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

旧时模样 提交于 2019-11-30 04:55:35

问题


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


回答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



回答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




回答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)


来源:https://stackoverflow.com/questions/39109224/self-image-frame-width-20-give-get-only-property-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!