UILabel 在行太长时自动换行
我的 UILabel 可以根据当前的 \n 进行换行。但如果行本身太长,它将无法自动换行。我可以对 UILabel 进行更多配置来实现这一目标吗?
我已经使用过:
aLabel.lineBreakMode = UILineBreakModeWordWrap;
aLabel.numberOfLines = 0;
[aLabel setFont:[UIFont fontWithName:@"MarkerFelt-Wide" size:24]];
aLabel.textAlignment = UITextAlignmentCenter;
CGRect labelFrame = aLabel.bounds;
labelFrame.size = [words sizeWithFont:aLabel.font constrainedToSize:CGSizeMake(LABEL_WIDTH, 100000) lineBreakMode:aLabel.lineBreakMode];
aLabel.frame = CGRectMake(0, 0, aLabel.frame.size.width-10, labelFrame.size.height);
words is a NSString
My UILabel can do a line break according to the current \n . But if the line itself is too long, it won't be able to automatically do a line break. Can I do more configurations to my UILabel to achieve that?
And I've already used:
aLabel.lineBreakMode = UILineBreakModeWordWrap;
aLabel.numberOfLines = 0;
[aLabel setFont:[UIFont fontWithName:@"MarkerFelt-Wide" size:24]];
aLabel.textAlignment = UITextAlignmentCenter;
CGRect labelFrame = aLabel.bounds;
labelFrame.size = [words sizeWithFont:aLabel.font constrainedToSize:CGSizeMake(LABEL_WIDTH, 100000) lineBreakMode:aLabel.lineBreakMode];
aLabel.frame = CGRectMake(0, 0, aLabel.frame.size.width-10, labelFrame.size.height);
words is a NSString
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据需要设置行数。
Set Number of line as you want to set.
如果您在段落中有文本并希望将其放置在具有不同行的标签中,则无需使用 UILineBreakModeWordWrap .. 只需编写一行代码即可将文本放置为多少行
if you are having text in a paragraph and want to place it in a lable with differ lines no need to use UILineBreakModeWordWrap.. simply write one line code as in how many lines you want to place the text as