如何设置UITextView的字体大小?

时间:2022-12-26 23:42:19

I have to set the font size and font family of a dynamically created textView, so that it gives same appearance as the one generated using Interface builder. Any idea how to do this?

我必须设置动态创建的textView的字体大小和字体系列,以便它与使用“接口”构建器生成的外观具有相同的外观。知道怎么做吗?

6 个解决方案

#1


7  

There is a property called font in UITextView,

在UITextView中有一个名为font的属性,

@property(nonatomic, retain) UIFont *font

You can do like this:

你可以这样做:

 yourTextView.font = builderTextView.font

#2


24  

UITextView *textView

...

[textView setFont:[UIFont fontWithName:@"ArialMT" size:16]]

#3


13  

You try this

你试试这个

[textView setFont:[UIFont systemFontOfSize:15]];

or

要么

[textView setFont:[UIFont boldSystemFontOfSize:15]];

or you want to give fontname and size then you try this

或者你想给出字体名称和大小然后你试试这个

[textView setFont:[UIFont fontWithName:@"arial" size:16]]

#4


5  

may be I am too late but wanted to post my answer as its most relevant with current SDK. I have used following line of code and work like charm in iOS 8.0 Swift Version:

可能是我为时已晚,但希望将我的答案发布为与当前SDK最相关的答案。我在iOS 8.0 Swift版本中使用了以下代码行并且像魅力一样工作:

self.textView.font = [UIFont systemFontOfSize:fontSize];

where fontSize is CGFloat Value.

其中fontSize是CGFloat Value。

#5


1  

In IB, select the text area and use the inspector to set the editability (it’s next to the text color). To set the font, you have to bring up the font window (command-T). It may help to have some text in the view when you change the font and size.

在IB中,选择文本区域并使用检查器设置可编辑性(它位于文本颜色旁边)。要设置字体,您必须调出字体窗口(command-T)。更改字体和大小时,在视图中显示一些文本可能会有所帮助。

#6


0  

textView.font = UIFont(name: "Times New Roman", size: 20)

This worked for me (Swift 4 using in Swift Playgrounds on Xcode).

这对我有用(Swift 4在Xcode上使用Swift Playgrounds)。

#1


7  

There is a property called font in UITextView,

在UITextView中有一个名为font的属性,

@property(nonatomic, retain) UIFont *font

You can do like this:

你可以这样做:

 yourTextView.font = builderTextView.font

#2


24  

UITextView *textView

...

[textView setFont:[UIFont fontWithName:@"ArialMT" size:16]]

#3


13  

You try this

你试试这个

[textView setFont:[UIFont systemFontOfSize:15]];

or

要么

[textView setFont:[UIFont boldSystemFontOfSize:15]];

or you want to give fontname and size then you try this

或者你想给出字体名称和大小然后你试试这个

[textView setFont:[UIFont fontWithName:@"arial" size:16]]

#4


5  

may be I am too late but wanted to post my answer as its most relevant with current SDK. I have used following line of code and work like charm in iOS 8.0 Swift Version:

可能是我为时已晚,但希望将我的答案发布为与当前SDK最相关的答案。我在iOS 8.0 Swift版本中使用了以下代码行并且像魅力一样工作:

self.textView.font = [UIFont systemFontOfSize:fontSize];

where fontSize is CGFloat Value.

其中fontSize是CGFloat Value。

#5


1  

In IB, select the text area and use the inspector to set the editability (it’s next to the text color). To set the font, you have to bring up the font window (command-T). It may help to have some text in the view when you change the font and size.

在IB中,选择文本区域并使用检查器设置可编辑性(它位于文本颜色旁边)。要设置字体,您必须调出字体窗口(command-T)。更改字体和大小时,在视图中显示一些文本可能会有所帮助。

#6


0  

textView.font = UIFont(name: "Times New Roman", size: 20)

This worked for me (Swift 4 using in Swift Playgrounds on Xcode).

这对我有用(Swift 4在Xcode上使用Swift Playgrounds)。