UILabel文本ios之前和之后的多余空间 [英] UILabel extra spaces before and after text ios

查看:93
本文介绍了UILabel文本ios之前和之后的多余空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标签以纵向模式完美显示文字.
当设备从纵向旋转到横向或从横向旋转到纵向时,它也可以正常工作.

Label shows text perfectly in portrait mode.
It also works properly when device rotates from portrait to landscape or landscape to portrait.

但是当我以横向模式打开应用程序时,它会在文本前后显示多余的空格.

But when i open app in landscape mode it shows extra spaces before and after the text.

我用过NumberOfLines = 0sizeToFit.
并尝试过

I have used NumberOfLines = 0 and sizeToFit.
and also tried

CGSize aSize = [self.label sizeThatFits:CGSizeMake(self.label.frame.size.width, CGFLOAT_MAX)];
self.label.frame = CGRectMake(self.label.frame.origin.x, self.label.frame.origin.y, self.label.frame.size.width, aSize.height);

您可以在此处查看图像: http://picpaste.com/Screen_Shot_2014-02-14_at_4.44.42_PM-7I55uWNF .png

You can check image here: http://picpaste.com/Screen_Shot_2014-02-14_at_4.44.42_PM-7I55uWNF.png

推荐答案

在您的UIViewController上添加此代码

Add this code on your UIViewController

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [myLabel sizeToFit];
    [self.view layoutIfNeeded];

    myLabel.preferredMaxLayoutWidth = myLabel.frame.size.width;
    [self.view layoutIfNeeded];
}

这篇关于UILabel文本ios之前和之后的多余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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