我想在 tableView:cellForRowAtIndexPath:
中设置我的 UITableViewCell 标签的框架宽度:我怎么会收到错误。
这就是我尝试设置单元格的方式。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell.textLabel setLineBreakMode:UILineBreakModeCharacterWrap];
cell.textLabel.frame.size.width = 200.0; // just as an example.
[cell.textLabel setMinimumFontSize:FONT_SIZE];
[cell.textLabel setNumberOfLines:0];
[cell.textLabel setFont:[UIFont boldSystemFontOfSize:FONT_SIZE]];
[cell.textLabel setTag:1];
[[cell contentView] addSubview:cell.textLabel];
}
但是在我尝试设置 textLabel.frame.size.width
的那一行我得到了这个错误
表达式不可赋值
最佳答案
这是不言而喻的,因为您无法更改 UITableViewcell
的 width
和 height
属性。更重要的是,您无法更改UITableViewCell
中的 textLabel
框架。您应该自定义 UITableViewCell
类。
关于iphone - UITableViewCell textLabel 宽度大小错误 Expression is not assignable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12189824/