而且我需要红色条的宽度适合所有设备上的 2 个图像(按钮)。
我一直在寻找答案,但我还没有找到任何有用的东西。
这是我正在使用的代码:
_background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 353, 20)];
[self addSubview:_background];
[self sendSubviewToBack:_background];
[_background setBackgroundColor:[UIColor redColor]];
_background.layer.cornerRadius = 10;
_background.clipsToBounds = YES;
_background.center = CGPointMake(200, 15);
_background.keepLeftOffsetTo(_sendButton);
_background.keepCenterAlignTo(self);
[_background updateConstraintsIfNeeded];
可能很容易解决这个问题,但我才使用 Objective-C 大约一个月! (来自 Android Java)。
现在任何帮助都会很棒
谢谢
更新 #1:我已经尝试按照建议使用 Masonry,但我仍然无法实现我的需要。
最佳答案
因此,为了帮助我快速设置 Storyboard并复制我需要的内容,然后我查看了 Storyboard中的约束,然后以编程方式复制它。像这样:
[background mas_remakeConstraints:^(MASConstraintMaker * make) {
make.trailingMargin.equalTo(_sendButton);
make.rightMargin.equalTo(@30);
make.leading.equalTo(_optionsButton);
make.leading.leadingMargin.equalTo(@25);
make.height.equalTo(@20);
make.center.equalTo(self);
}];
如您所知,我最终确实使用了 Masonry 来完成此操作。
关于ios - UIView:如何使宽度在另一个图像之前自动结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44418127/