简体   繁体   中英

How can I set the font size of UITextView?

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?

UITextView *textView

...

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

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]]

There is a property called font in UITextView ,

@property(nonatomic, retain) UIFont *font

You can do like this:

 yourTextView.font = builderTextView.font

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:

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

where fontSize is CGFloat Value.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM