【问题标题】:How to align UILabel's baseline to the bottom of a UIImageView?如何将 UILabel 的基线对齐到 UIImageView 的底部?
【发布时间】:2014-12-10 19:31:38
【问题描述】:

我正在尝试将 UILabel 的基线与 UIImageView 的底部对齐。我发现我无法选择标签的基线作为标签的属性。但是,我还发现如果用另一个标签替换图像视图,我可以使用基线。

有没有办法将标签的基线与图像的底部对齐?

【问题讨论】:

    标签: ios xcode autolayout


    【解决方案1】:

    编辑:使用最新版本的 Xcode,您可以随心所欲。

    上一个答案: 您可以通过以下方式以编程方式执行此操作:

    NSLayoutConstraint *layoutConstraint = [NSLayoutConstraint 
        constraintWithItem:_imageView 
                 attribute:NSLayoutAttributeBottom
                 relatedBy:NSLayoutRelationEqual 
                    toItem:_textLabel 
                 attribute:NSLayoutAttributeBaseline 
                multiplier:1.0f
                  constant:0];
    [self.view addConstraint:layoutConstraint];
    

    【讨论】:

      【解决方案2】:

      有些事情是 nib 编辑器不允许你做的。您需要在代码中配置该约束。

      【讨论】:

        猜你喜欢
        • 2020-11-13
        • 1970-01-01
        • 1970-01-01
        • 2011-01-02
        • 1970-01-01
        • 2013-08-17
        • 1970-01-01
        • 2016-01-12
        • 1970-01-01
        相关资源
        最近更新 更多