我试图在导航栏中有两个UILabel而不是一个.
我按照此链接获取有关如何执行此操作的信息: 导航栏中的iPhone标题和副标题
它运作良好,但我不能让我的文本正确居中.它在按钮之间居中,但默认的标题行为是在正确的时间内居中.
我看了一下,同样的问题,但没有回答: UINavigationBar TitleView带副标题
我错过了什么?这是我的代码:
CGRect headerTitleSubtitleFrame = CGRectMake(0, 0, 200, 44);
UIView* _headerTitleSubtitleView = [[UILabel alloc] initWithFrame:headerTitleSubtitleFrame];
_headerTitleSubtitleView.backgroundColor = [UIColor clearColor];
_headerTitleSubtitleView.autoresizesSubviews = NO;
CGRect titleFrame = CGRectMake(0, 2, 200, 24);
UILabel *titleView = [[UILabel alloc] initWithFrame:titleFrame];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20];
titleView.textAlignment = NSTextAlignmentCenter;
titleView.textColor = [UIColor whiteColor];
titleView.shadowColor = [UIColor darkGrayColor];
titleView.shadowOffset = CGSizeMake(0, -1);
titleView.text = @"Title";
titleView.adjustsFontSizeToFitWidth = YES;
[_headerTitleSubtitleView addSubview:titleView];
CGRect subtitleFrame = CGRectMake(0, 24, 200, 44-24);
UILabel …Run Code Online (Sandbox Code Playgroud) 是否有可能有一个UILabel由多个\n分隔线组成的线,使其宽度 > 标签宽度被截断而不是包裹?
假设我有一些类似以下的文本:
我希望这出现在我的UILabel样子:
1. 这是一个很长的第一行文本... 2. 短线 3. 另一条短线
然而,发生的事情是我得到了这个:
1. 这是一段很长的第一行文字 太长而无法水平放置 2. 短线...
第三行正在被切断。我已将行数设置为3,但它仍在包装第一条长行。我在标签上设置换行符属性的内容似乎并不重要——它总是包含第一行。有什么办法可以防止完全包裹在标签上?