Neha Purwar Neha Purwar - 6 months ago 17
iOS Question

fontSize are not working properly

I have created an application in which I have added text into a video through `UITextView. It's displaying properly but the problem is that I have set the text font size like this:

[textView setFont: [UIFont fontWithName:@"Helvetica" size:35]];


and it works for the font sizes 18,20 but it isn't working properly for large font sizes like 30 , 35, etc.

Code for creating textview programmatically:

UITextView *textView =[[UITextView alloc] init];
textView.text = @"text here";
[textView setFont: [UIFont fontWithName:@"Helvetica" size:35]];
[textView setBackgroundColor: [UIColor redColor]];
[textView setTextColor: [UIColor whiteColor]];
textView.frame=CGRectMake(35,35,500,500);
textView.transform = CGAffineTransformMakeRotation(M_PI_2);
[textView setReturnKeyType:UIReturnKeyDone];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:textView];

Answer

Use this code,

    UITextView *textView =[[UITextView alloc] init];
    textView.text = @"text here";
    [textView setFont:[UIFont systemFontOfSize:90]];
    textView.delegate = self;
    [textView setBackgroundColor: [UIColor redColor]];
    [textView setTextColor: [UIColor whiteColor]];
    textView.frame=CGRectMake(20,35,self.view.frame.size.width-40,200);
    [textView setReturnKeyType:UIReturnKeyDone];
    textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [self.view addSubview:textView];

You set the frame size wrong, In Iphone width size is 360 to 414 only, but you give 500, the above working for me, see the output,

enter image description here

hope its helpful

Comments