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

a 夏天 提交于 2019-11-30 21:36:02

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

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

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