在两个其他标签之间垂直居中 UILabel [英] vertically center UILabel between two other lables

查看:55
本文介绍了在两个其他标签之间垂直居中 UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在故事板中绘制了 3 个 UILabel,它们彼此重叠.

I have 3 UILabels drawn in storyboard positioned on top of each other.

静态 UI 标签 1

动态界面标签 2

静态 UI 标签 3

标签 1 和 3 是静态的,永远不会改变.标签 2 是动态的,总是一个句子长,但可以是一个短句或长句换行.我希望标签 2 根据有多少文本在标签 1 和标签 3 之间完全垂直居中.任何想法如何做到这一点?非常感谢!

Labels 1 and 3 are static and never change. Label 2 is dynamic and is always one sentence long, but could be a short or long sentence that wraps. I want Label 2 to be perfectly vertically centered between label 1 and label 3 based on how much text is there. Any ideas how to do this? Greatly appreciated!

推荐答案

如果您使用自动布局(默认情况下处于启用状态),那么您只需拉伸中间标签,直到它的顶部和底部距离标准距离来自其他两个标签(当您到达该距离时,您将看到一条蓝色虚线).这假设您的标签具有清晰的背景,或者如果没有,您不介意看到高标签.无论行数如何,文本都将在此高标签中垂直居中.它也将保持以旋转为中心.

If you're using auto layout (which is on by default), then you can just stretch the middle label until it's top and bottom are the standard distance away from the other two labels (you will see a dotted blue line when you reach that distance). This assumes that your label has a clear background, or that you don't mind seeing a tall label if it doesn't. The text will be centered vertically in this tall label regardless of the number of lines. It will also stay centered on rotation.

这篇关于在两个其他标签之间垂直居中 UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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