我试图将UILabel实例标签放在UITextField实例文本字段旁边,就像在iOS设置对话框中完成一样.我在Florian Kuglers FLKAutoLayout扩展(https://github.com/dkduck/FLKAutoLayout)的帮助下使用自动布局和约束.

当我只设置标签的前导约束和标签与文本字段之间的空间约束时,标签和文本字段宽度会根据其内容进行调整.(下图)
但是当我为文本字段设置了一个尾随约束时,只有textfields宽度会调整为其内容,但标签会被拉伸.(上图)
我希望表现相反,以便文本字段将被拉伸,标签将调整为其内容.为什么iOS决定拉伸标签而不是文本字段?
[self addSubview:self.label];
[self addSubview:self.textField];
[self.label alignLeadingEdgeWithView:self predicate:@"10"];
[self.textField constrainLeadingSpaceToView:self.label predicate:@"10"];
// difference between top and bottom pciture
// [self.textField alignTrailingEdgeWithView:self predicate:@"-25"];
Run Code Online (Sandbox Code Playgroud) 我已经使用autolayout几个星期了.目前,我正在使用名为FLKAutoLayout的第三方库,这使得该过程更容易.我正处于可以按照我想要的方式构建视图的地步,通常没有问题.然而,在过去4天的工作中,一旦参与了控制器,我就一直在努力进行自动布局.我对各种各样的UIViews很好......但出于某种原因,每个viewcontroller.view都是一个完全的恶魔.我只得到一个问题,让viewcontroller.view以我想要的方式调整大小,而更深层次的问题是,当使用autolayout时,子视图控制器的UIViews没有正确接收事件.子视图控制器在手动指定帧时工作得很好,但是一切都因autolayout而崩溃.
我不明白viewcontroller的UIView有什么不同之处让它与其他所有人不同......我的思绪正在沮丧地融化.ios是否在幕后或其他东西搞乱了我的viewcontroller视图?
示例图片http://i39.tinypic.com/6qeh3r.png
在图像中,红色区域属于子视图控制器.这个区域不应该超过最底部的子视图(表示三个的卡).这应该很简单,我可以通过一堆普通的UIViews使它工作得很好但是因为这是一个viewcontroller,一切都会破坏......
任何人都可以阐明我不知道的是什么.任何潜在问题的线索都非常感谢.
谢谢阅读.
更新:问题可能与模棱两可的约束有关
UIView *box = [[UIView alloc]init];
[box addSubview:imageView];
[box addSubview:nameLabel];
imageView constrainWidth:@"32" height:@"32"];
[imageView alignTop:@">=0" leading:@"0" bottom:@"<=0" trailing:@"<=0" toView:box];
[imageView alignCenterYWithView:box predicate:@"0"];
[nameLabel constrainLeadingSpaceToView:imageView predicate:@"5"];
[nameLabel alignTop:@">=0" leading:@">=0" bottom:@"<=0" trailing:@"<=0" toView:box];
[nameLabel alignCenterYWithView:box predicate:@"0"];
[self addSubview:box];
[box alignTop:@"5" leading:@"5" bottom:@"-5" trailing:@"-5" toView:self];
Run Code Online (Sandbox Code Playgroud)
上面的例子是一个模棱两可的布局,但我无法弄清楚它有什么问题......
viewcontroller ios autolayout childviewcontroller flkautolayout