iphone - UITableViewCell textLabel 宽度大小错误 Expression is not assignable

标签 iphone ios uitableview textlabel

我想在 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 的那一行我得到了这个错误

表达式不可赋值

最佳答案

这是不言而喻的,因为您无法更改 UITableViewcellwidthheight 属性。更重要的是,您无法更改UITableViewCell 中的 textLabel 框架。您应该自定义 UITableViewCell 类。

关于iphone - UITableViewCell textLabel 宽度大小错误 Expression is not assignable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12189824/

相关文章:

iPhone 随机数附加 URL

ios - 未调用 audioRecorderBeginInterruption

iphone - 如何从它创建的对象中引用 Controller ?

ios - 单击ios中的单元格时如何旋转可扩展单元格中的图像?

iphone - UITableViewCell 中的多种颜色

ios - 在 iOS 设备上本地解析和存储对象

iphone - 跨平台手机开发环境

ios - 如何在 iOS 中为 UITabBarController 的更多 View Controller 设置 selectedindex

ios - 如何在swift中加密sqlite数据

ios - 添加表格 View 单元格遵循 1 个自定义样式?