46

can any one help to change the font size in UITextView.

[textView setFont:[UIFont fontWithName:@"ArialMT" size:30]];

I use this one but it doesn't work.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
mychar
  • 1,031
  • 1
  • 11
  • 20

7 Answers7

74

Have you bind textView with xib or allocated textView?

If yes,

You can use following code to check whether this works

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

or

 [textView setFont:[UIFont systemFontOfSize:15]];
jigneshbrahmkhatri
  • 3,627
  • 2
  • 21
  • 33
  • 7
    This works, but it is really strange that font changing in storyboard has no effect. – Stan Nov 19 '13 at 16:54
  • 4
    @iMOBDEV I'd add the swift case also, it helped to me ;): textView.font = UIFont.systemFontOfSize(16.0) – Nicholas Feb 10 '15 at 20:44
62

Check, if "Selectable" is checked in the xib/Storyboard attribute inspector. If it's not selectable, the size wont be changed

brainray
  • 12,512
  • 11
  • 67
  • 116
17

Swift 4.0

textField.font = UIFont.systemFont(ofSize: 17.0)
Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
9
   UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
   [textView  setFont: [UIFont fontWithName:@"ArialMT" size:30]];
   textView.text = @"test my font size";
   [self.view addSubview:textView];
   [textView release];

Your code is correct. The problem is from other part of your code. Provide more details about your textView

Set custom font and size in Swift:

textView.font = UIFont(name: "ArialMT", size: 20)
Alex Terente
  • 12,006
  • 5
  • 51
  • 71
4

Use this:

UITextView *myTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];  
myTextView.font = [UIFont fontWithName:@"arial" size:14];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
3

Here is for swift 3.0

textview.font = UIFont(name: textview.font.fontName, size: 18)
Dhruv Khatri
  • 803
  • 6
  • 15
1

I tried it the same way like you with

[textView setFont:[UIFont fontWithName:kFontName size:kFontSize]];

I set the UITextView inside ViewDidLoad. My problem was, I transformed my view:

[_viewEnd setTransform:CGAffineTransformMakeScale(0.0, 0.0)];

My problem was solved with setting the properties of the UITextView after transforming my UIView which includes the UITextView.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74