gpt4 book ai didi

ios - 将 UILabel 剪辑到 UIImageView

转载 作者:行者123 更新时间:2023-11-29 02:10:43 25 4
gpt4 key购买 nike

我正在尝试在 UIImageView 中创建一个 UILabel,但它不适合 UIImageView 边界。我可以在纵向运行时将其设置得很好,但是当我将设备转为横向时,它似乎失去了方向并且出现在 UIImageView 之外。

有什么方法可以将 UILabel 剪辑到 UIImageView 中吗?

最佳答案

您可以通过向标签和 ImageView 添加适当的约束来实现它。下面是一个示例代码,可以从 imageview 的左侧、右侧和底部修复标签:

//左右对齐 yourLabel

[yourImageview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[yourLabel]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(yourLabel)]];

//从底部对齐 yourLabel

[yourImageview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[yourLabel]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(yourLabel)]];

关于ios - 将 UILabel 剪辑到 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29313209/

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