iOS - UILabel 与 UITextAlignmentLeft 剪辑积分符号 ∫如果它是文本的第一个字符
以下基本上是我的整个项目来说明问题:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILabel *integralLabel = [[UILabel alloc]initWithFrame: CGRectMake(30, 60, 200, 150)];
integralLabel.font = [UIFont systemFontOfSize:100];
[window addSubview:integralLabel];
integralLabel.text = @"∫∫∫";
integralLabel.textAlignment = UITextAlignmentLeft;
integralLabel.backgroundColor = [UIColor yellowColor];
[window makeKeyAndVisible];
return YES;
}
标签中最左边的积分符号被剪掉。
有没有一种干净的方法来解决这个问题?我的标签内容会根据各种各样的事情而经常改变,所以我不想做一些黑客的事情。
The following is basically my entire project to illustrate the problem:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILabel *integralLabel = [[UILabel alloc]initWithFrame: CGRectMake(30, 60, 200, 150)];
integralLabel.font = [UIFont systemFontOfSize:100];
[window addSubview:integralLabel];
integralLabel.text = @"∫∫∫";
integralLabel.textAlignment = UITextAlignmentLeft;
integralLabel.backgroundColor = [UIColor yellowColor];
[window makeKeyAndVisible];
return YES;
}
The leftmost integral sign in the label is clipped.
Is there a clean way to fix this? The contents of my labels will change frequently in response to all sorts of things, so I don't want to do something hackish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果文本以积分符号开头,您可以在开头添加一个空格:
编辑
要区分此空格和标签中的其他空格,您可以对空格使用不同的 Unicode 值(完整列表如下: http://www.cs.tut.fi/~jkorpela/chars/spaces .html)
等...
编辑2
您还可以通过重写
drawTextInRect:
来子类化UILabel。希望这有帮助。
You can add a space at the beginning if the text begins with the integral sign:
EDIT
To distinguish between this space and other spaces in the label, you can use different Unicode values for spaces (full list here: http://www.cs.tut.fi/~jkorpela/chars/spaces.html)
etc...
EDIT 2
You can also subclass UILabel by overriding
drawTextInRect:
.Hope this helps.