将 UILabel 的文本设置为粗体
我想让 UILabel 的文本变为粗体
infoLabel=[[UILabel alloc]initWithFrame:CGRectMake(90,150, 200, 30)];
[infoLabel setText:@"Drag 14 more Flavors"];
[infoLabel setBackgroundColor:[UIColor clearColor]];
[infoLabel setFont:[UIFont fontWithName:@"Arial" size:16]];
[infoLabel setTextColor:[UIColor colorWithRed:193.0/255
green:27.0/255
blue:23.0/255
alpha:1 ]];
I want to make UILabel's text bold
infoLabel=[[UILabel alloc]initWithFrame:CGRectMake(90,150, 200, 30)];
[infoLabel setText:@"Drag 14 more Flavors"];
[infoLabel setBackgroundColor:[UIColor clearColor]];
[infoLabel setFont:[UIFont fontWithName:@"Arial" size:16]];
[infoLabel setTextColor:[UIColor colorWithRed:193.0/255
green:27.0/255
blue:23.0/255
alpha:1 ]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果你想保留系统字体并将其设置为粗体:
If you want to retain the system font and make it bold:
尝试
一下可能还值得检查您尝试使用的字体是否在设备上可用
Try
It may also be worth checking if the font you're trying to use is available on device
使用 Xcode 中的 GUI 选择标签,然后转到属性检查器。选项之一是字体。单击字体图标(而不是上下箭头)。在出现的弹出窗口中展开“字体组合框”。在粗体系统部分下选择常规。
Using the GUI in Xcode select the label then go to the Attributes Inspector. One of the options is Font. Click on the font icon (not the up-down arrows). In the popup that appears expand the Font ComboxBox. Under the Bold System section choose Regular.
对于快速用户来说,这应该可行:
或者如果您想使用不同的字体:
For swift users this should work:
or if you'd like to use a different font:
在可能的情况下,我建议使用动态字体大小来为用户提供最佳的可访问性。
您可以通过执行以下操作使标签使用系统动态字体并将其设置为粗体文本:
Where possible I would suggest using dynamic font sizes to provide the best possible accessibility to your users.
You can make a label use a system dynamic font and set it to have bold text by doing the following:
如果您没有自定义字体的粗体变体,您可以将笔划设置为负值以产生粗体效果。请参阅此处:
如何同时描边和填充与 NSAttributedString w/ UILabel
You can set the stroke with a negative value to make a bold effect if you don't have the bold variation of your custom font. See here:
How can I both stroke and fill with NSAttributedString w/ UILabel
如果您想使用具有动态字体和粗体样式的 UILabel,请首先按如下方式扩展 UIFont。
然后为标签指定字体,如下所示:
If you wanna use UILabel with a dynamic font but also with a bold style, first extend UIFont as below.
Then assign a font to label like this: