vertically center align text in the UIlabel

I want the text written in the UILabel to be aligned center vertically.

How can I do that? My label's name is phoneLabel. Here I am attaching an image:

See the phone number, the label is completely aligned with the whatsapp image but the text does not look good as it is not aligned vertically centered.

Here are the contraints:


Problem is here you added top space = 6 for UILabel remove it. Add center vertical constraints to image.

Additionally if you have setted leading & trailing then no need of width constraints.

Make sure below things

  • Set constraints to phoneLabel which is center vertically to your whatsapp image.
  • Set your UILabel content/text alignment to be Center.
  • Remove top & bottom spacing of UILabel . Only these constraints enough height,center vertical to image,leading & trailing spaces.
  • 链接地址: http://www.djcxy.com/p/4848.html

    上一篇: 蟒蛇

    下一篇: 垂直居中对齐UIlabel中的文本