ios - 在 UIView 中将一个 ImageView 和一个 UILabel 居中

标签 ios uiview uiimageview uibutton uilabel

如果我声明了一个不同大小的 UILabel 和一个 UIImageView,我可以将它们置于 UIView 的中心,两者之间的水平间距为 10.0points 吗?

谢谢!

最佳答案

是的,你可以。基本上你需要的是适当的约束。您可以从代码或 Storyboard中添加约束

代码示例:

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:5];
[view addConstraint:constraint];

NSLayoutConstraint Documentation

Auto Layout Tutorial

Adaptive Layout Tutorial

关于ios - 在 UIView 中将一个 ImageView 和一个 UILabel 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28895227/

相关文章:

objective-c - 如何在iOS中获取系统图标

ios - 为什么 ios6 破坏了我的 View

iphone - 强制 UIView 立即重绘,而不是在下一个运行循环期间重绘

ios - 访问 Storyboard 中的 View

ios - 是否可以在 block 中绘制 CGContext ?

ios - 避免在我的 UIImageView 中拉伸(stretch) UIImage

ios - 如何使用雅虎!在 iOS 应用程序中联系 api?

ios - 在代码中使用静态单元格重新排序 UITableview

iphone - 如何在ios中的动态创建中水平重复图像

objective-c - 将 uiimage 拖放到另一个 uiimageview 中