如何使该UILabel将电子邮件地址移至下一行? [英] How to make this UILabel move the email address to the next Line?

查看:144
本文介绍了如何使该UILabel将电子邮件地址移至下一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的UILabel,它按如下方式打印文本:

I have a simple UILabel that is printing text as follows:

John Doe sent a message to blahblah-
blah@blahblah.com

因此,此处的电子邮件地址:blahblah-blah@blahblah.com被剪切并部分显示在下一行上.我需要怎么做才能使其显示为:

Thus, the email address here : blahblah-blah@blahblah.com is being cut and partially displayed on the next line. What do I need to do to make it display as :

John Doe sent a message to 
blahblah-blah@blahblah.com    

?

我已经有以下内容:

self.mailLabel.lineBreakMode = NSLineBreakModeByWordWrapping;
self.mailLabel.numberOfLines = 0;

有问题的字符串是:

[NSString stringWithFormat:@"You sent a message to %@", emailAddress];

我应该在这里做什么?请记住,名称可能很长,因此,在字符串中添加换行符将不起作用,因为我不希望出现以下情况:

What should I do here? Remember, the name can be long and hence, adding a line break in the string won't work because I don't want the following case :

Jonathon Dawson sent a message
to 
blahblah-blah@blahblah.com   

应为

Jonathon Dawson sent a message
to blahblah-blah@blahblah.com   

推荐答案

您需要在-(连字符)的左侧和右侧添加 ZWNBSP (零宽度不间断空格)字符,又称破折号)符号:

You need to add ZWNBSP(Zero-width no-break space) characters to the left and to the right of - (hyphen, aka dash) symbol:

self.mailLabel.text = [self.mailLabel.text stringByReplacingOccurrencesOfString:@"-" withString:@"\u2060-\u2060"];

备注:

U + 2060 -零宽度不间断空格Unicode字符可防止可能被插入程序在其前后包裹该单词的任何换行符.一旦UILabel(以及Cocoa中的其他文本控件)遵守Unicode,您将获得不带意外换行符的文本.

U+2060 - Zero-width no-break space Unicode character prevents any line breaks that may be inserter to wrap the word before and after it. As soon as UILabel (as well as other text controls in Cocoa) respects Unicode, you will get text without undesired line breaks.

Wikipedia链接: http://en.wikipedia.org/wiki/Zero-width_no -break_space

Wikipedia link: http://en.wikipedia.org/wiki/Zero-width_no-break_space

这篇关于如何使该UILabel将电子邮件地址移至下一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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