3

我有一个使用自定义 UITableViewCell 的表格视图。单元格包含需要在单元格中右对齐的 UILabel。

这是一个 iPad 应用程序。我将自定义单元格设计为默认适合纵向(768 宽度)。问题是当应用程序旋转到横向时,UILabel 不会停留在右侧。我什至进行了测试,以确保单元格本身正确拉伸到横向宽度。

无论我做什么,它似乎都只想相对于左侧对齐。在 IB 的约束中,我选择了“Trailing Space to Superview”,但它似乎没有做任何事情。IB 自动将水平间距 (651) 设置为从左侧偏移。我无法删除此约束。

这真的很难做到还是我只是错过了一些非常明显的东西?

4

1 回答 1

0

【这边走Cell IBoutlet】

1.从ios/User interface/Empty添加新文件。2. 从对象中添加表格视图单元格并在其中添加标签。2.给标签标签1加上设置对齐权(如下图所示)

  [1]: http://i.stack.imgur.com/8AzJH.png

现在在您的 tableview 委托方法中添加以下行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *cellid =@"Cellid";

    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellid];
    if(cell==nil){

        cell =[[[NSBundle mainBundle] loadNibNamed:@"cell" owner:self options:nil] objectAtIndex:0];
        //[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];

    }
    UILabel *celllabel = (UILabel*)[cell viewWithTag:1];
    celllabel.text =@"Test label alignment";
    return cell;
}

这对我来说非常有用。

于 2013-08-26T06:50:43.647 回答