首页 > 解决方案 > 无法分配给属性:“宽度”是仅获取属性

问题描述

我是斯威夫特的新手。我收到此错误:

无法分配给属性:“宽度”是仅获取属性

使用此语句时:

 cell.reciverMsg.frame.width = cell.reciverMsg.text?.characters.count * 2

reciverMsg是一个UILabel

标签: iosswiftuilabel

解决方案


您需要设置width框架的size属性。

cell.reciverMsg.frame.size.width = 20

width属性frame只是一个只读的方便。有关详细信息,请参阅文档CGRect


推荐阅读