Neha Purwar
Neha Purwar

Reputation: 175

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];

Upvotes: 0

Views: 64

Answers (3)

Iyyappan Ravi
Iyyappan Ravi

Reputation: 3245

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

Upvotes: 1

Iyyappan Ravi
Iyyappan Ravi

Reputation: 3245

Use this Code,

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

or

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

And also set the delegate in UITextview

textView.delegate=self;

give the delegate in top of the class, example

@interface ViewController1 : UIViewController <UITextViewDelegate>

hope its helpful

Upvotes: 1

user5938635
user5938635

Reputation:

I am not sure but try this code

[textView setFont:[UIFont systemFontOfSize:35]];

Upvotes: 0

Related Questions