gpt4 book ai didi

ios - 无法使用约束右对齐 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:39 26 4
gpt4 key购买 nike

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

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

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

这真的有那么难吗,还是我只是漏掉了一些非常明显的东西?

最佳答案

[沿这条路走Cell IBoutlet]

1.从 ios/User interface/Empty 添加新文件。2. 从对象中添加表格 View 单元格并在其中添加标签。2.给label标签1加上Set alignment right(如下图所示)

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

现在在你的 tableview 委托(delegate)方法中添加下面一行

- (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;
}

它非常适合我。

关于ios - 无法使用约束右对齐 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18436119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com