xcode 带有字体名称和粗体的 UITextView 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7203265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:48:56  来源:igfitidea点击:

UITextView formatting with fontname and bold

objective-ciosxcodeuitextview

提问by Yogesh Agarwal

In a UITextView is it possible to set the fontname and then set it to bold?

在 UITextView 中是否可以设置字体名称然后将其设置为粗体?

I know that font name and size can be set using fontWithName:(NSString *)fontName size:(CGFloat)fontSize

我知道可以使用 fontWithName:(NSString *)fontName size:(CGFloat)fontSize 设置字体名称和大小

But once this is done how can i make it bold?

但是一旦这样做了,我怎样才能让它变得大胆呢?

回答by Gyani

The system font on the iPhone is a good choice for many purposes. You can easily select it in a regular, bold or italic style using built-in font class methods. For example

iPhone 上的系统字体是多种用途的不错选择。您可以使用内置字体类方法以常规、粗体或斜体样式轻松选择它。例如

  UIFont *mainTitleFont = [UIFont boldSystemFontOfSize:14.0];
  UIFont *subTitleFont = [UIFont SystemFontOfSize:14.0];
  UIFont *textFont = [UIFont italicSystemFontOfSize:12.0];

But what if you want a font using both bold and italic at the same time, or a different typeface altogether? In that case, you can use the “fontWithName” method as follows.

但是,如果您想要一种同时使用粗体和斜体的字体,或者完全不同的字体怎么办?在这种情况下,您可以使用“fontWithName”方法如下。

  UIFont *altFont = [UIFont fontWithName:@"Courier-Bold" size:14.0];

Reference

参考

回答by Tomas Vana

Use the Bold variant of the font, e.g. @"Helvetica-Bold"as the fontName. If using the default system font is ok for you, you can also use boldSystemFontOfSize:method instead.

使用字体的粗体变体,例如@"Helvetica-Bold"作为fontName. 如果使用默认系统字体对您来说没问题,您也可以使用boldSystemFontOfSize:method 代替。

回答by PJR

UIFont *f = [UIFont fontWithName:@"Verdana-Bold" size:12];
yourTextView.font = f;

回答by MinuMaster

If you want to give font with name then you can refer below link. It have all font which are provided by iOS with their font names.

如果你想给字体加上名字,那么你可以参考下面的链接。它具有 iOS 提供的所有字体及其字体名称。

iOS Fonts

iOS 字体

Thanks.

谢谢。