Reputation: 327
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?
Upvotes: 9
Views: 28675
Reputation: 31
textView.font = UIFont(name: "Times New Roman", size: 20)
This worked for me (Swift 4 using in Swift Playgrounds on Xcode).
Upvotes: 1
Reputation: 2857
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.
Upvotes: 5
Reputation: 18741
There is a property called font in UITextView,
@property(nonatomic, retain) UIFont *font
You can do like this:
yourTextView.font = builderTextView.font
Upvotes: 9
Reputation: 2219
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]]
Upvotes: 14
Reputation: 161
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.
Upvotes: 1
Reputation: 4878
UITextView *textView
...
[textView setFont:[UIFont fontWithName:@"ArialMT" size:16]]
Upvotes: 24