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
  • 56,735
  • 45
  • 213
  • 327
mychar
  • 1,001
  • 1
  • 11
  • 18

7 Answers7

73

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]];
iMOBDEV
  • 3,587
  • 2
  • 20
  • 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
61

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

brainray
  • 12,029
  • 11
  • 65
  • 113
16

Swift 4.0

textField.font = UIFont.systemFont(ofSize: 17.0)
Brian Ogden
  • 17,286
  • 8
  • 87
  • 164
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
  • 11,929
  • 5
  • 50
  • 70
4

Use this:

UITextView *myTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];  
myTextView.font = [UIFont fontWithName:@"arial" size:14];
Mick MacCallum
  • 126,953
  • 40
  • 282
  • 279
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
  • 5,896
  • 5
  • 41
  • 73