简体   繁体   中英

How to get UILabel to center text vertically?

I am assigning some text into a UILabel to display a single character, a symbol, with a Unicode value. Nothing unusual. But it is not being centered vertically when displayed. I've fiddled with settings, and then read several Stack Overflow questions and answers, but cannot get it to look right.

Here it is when the font is, I think, 14.0. I'm talking about the double-arrow symbol.

在此处输入图像描述

But when I increase the font to make the symbol more visible, notice the arrow is increasingly rendered downwards vertically, closer to the bottom than the top:

在此处输入图像描述

I am assigning the text like this:

lblMyLabel.text = [NSString stringWithFormat:@"\u21D4"];

The settings look like this:

在此处输入图像描述

The frames of the 3 labels you see are assigned according to the containing frame. It is very simple. The height of the problematic UILabel is the same as its containing view and same as the labels to its left and right. Each of the 3 labels is 1/3 of the width of the containing view. Notice the text in the labels on the left and right of the double-arrow symbol are centered fine vertically.

How to center the symbol vertically? Is there something special about a unicode symbol?

The problem was because I did not have Automatically Adjusts Font selected and then proper Autoshrink setting that should accompany it. In my case I used Minimum Font Size for the Autoshrink setting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM