在 UIView 中将 UIImageView 和 UILabel 居中 [英] Center a UIImageView and a UILabel together in a UIView

查看:29
本文介绍了在 UIView 中将 UIImageView 和 UILabel 居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我声明了一个不同大小的 UILabel 和一个 UIImageView,那么我可以将它们居中在一个 UIView 中,两者之间水平方向相差 10.0 点吗?

If I declare a UILabel and a UIImageView of different sizes can I then center them in a UIView with 10.0points between the two horizontally?

谢谢!

推荐答案

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

Yes you can. Basically what you need is appropiate constraints. You can add constraints from code or in stoaryboard

代码示例:

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

NSLayoutConstraint 文档

自动布局教程

自适应布局教程

这篇关于在 UIView 中将 UIImageView 和 UILabel 居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆