UILabel 字母被截断
我正在尝试在 UILabel 中使用特殊字符。但它正在取消标签。我放置了红色背景来显示标签边缘的位置。有什么原因可能会发生这种情况吗?我将 maskToBounds 和 ClipToBounds 设置为 NO;
CGSize lblSize = [FontHelper sizeForText:text withFont:[self getBodyFont] withWidth:kColumnWidth andNumberOfLines:1000];
UILabel*lbl = [[UILabel alloc] initWithFrame:CGRectMake(x,
y + body.frame.size.height - columnHeight - kBottomMargin,
kColumnWidth,
lblSize.height)];
lbl.clipsToBounds = NO;
lbl.layer.masksToBounds = NO;
lbl.text = text;
lbl.backgroundColor = [UIColor redColor];
lbl.font = [self getBodyFont];
lbl.textColor = [UIColor blackColor];
lbl.numberOfLines = 0;
lbl.textAlignment = UITextAlignmentLeft;
lbl.lineBreakMode = UILineBreakModeWordWrap;
I am trying to use a special character in the UILabel. But it is chopping off the labels. I put in a red background to show where the edge of the label is. Any reason why this may be happening? I have maskToBounds and clipToBounds set to NO;
CGSize lblSize = [FontHelper sizeForText:text withFont:[self getBodyFont] withWidth:kColumnWidth andNumberOfLines:1000];
UILabel*lbl = [[UILabel alloc] initWithFrame:CGRectMake(x,
y + body.frame.size.height - columnHeight - kBottomMargin,
kColumnWidth,
lblSize.height)];
lbl.clipsToBounds = NO;
lbl.layer.masksToBounds = NO;
lbl.text = text;
lbl.backgroundColor = [UIColor redColor];
lbl.font = [self getBodyFont];
lbl.textColor = [UIColor blackColor];
lbl.numberOfLines = 0;
lbl.textAlignment = UITextAlignmentLeft;
lbl.lineBreakMode = UILineBreakModeWordWrap;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我找到了解决方案。客户给了我 Word 文档中的上述文本,我将其复制并粘贴到该文件中。点和文本之间的空格看起来是一个空格,但实际上是其他特殊字符。所以复制/粘贴暴露了它丑陋的头。
I think I found the solution. The client had give me the above text in a Word Doc and I had copy and pasted into the file. The space between the dot and the text appeared to be a space but was other special character. So copy/paste flared its ugly head.
对于任何其他偶然发现这个问题的人,我也遇到了同样的问题,在我的例子中,UILabel 中有一些制表符,这导致了相同的效果。
For anyone else who stumbles on this question, I had the same problem and in my case there were a few tab characters in the UILabel, which caused the same effect.