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 t开发者_如何学编程o 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.
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.
textView.font = UIFont(name: "Times New Roman", size: 20)
This worked for me (Swift 4 using in Swift Playgrounds on Xcode).
精彩评论