Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView weird margin on top?

I have a UITextView and it has a weird margin at the top, not sure what's causing this. Here's the picture, the background is orange:

enter image description here

Here's my relevant code:

textViewTest = [[UITextView alloc] initWithFrame:CGRectMake(135, 0, 150, 68)];
[textViewTest setContentInset:UIEdgeInsetsZero];
[textViewTest setUserInteractionEnabled:NO];
[textViewTest setBackgroundColor:[UIColor orangeColor]];
[textViewTest setTextColor:[UIColor whiteColor]];
//[textViewTest setFont:[UIFont fontWithName:@"MuseoSans-500" size:12.0]];
[textViewTest setText:@"Spooky (rename)\nCreated: 4/10/11\nUpload Youtube\nDelete | Favorite"];

What I want is the text in UITextView (textViewTest) to not have any space from the top (margin). Currently, there's like 8-10 px from the top of the orange, then the text starts.

like image 988
0xSina Avatar asked Mar 18 '12 18:03

0xSina


2 Answers

If you only want to move the text, try

[textViewTest setContentInset:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];

Where a positive number moves the frame towards the middle, a negative moves it out from the middle.

For example, [textViewTest setContentInset:UIEdgeInsetsMake(-5, 0, 5,0)], will move the text 5 pixels up!

like image 90
Karl Eriksson Avatar answered Nov 14 '22 22:11

Karl Eriksson


In viewDidLoad add:

 self.automaticallyAdjustsScrollViewInsets = NO;
like image 43
Hsm Avatar answered Nov 14 '22 23:11

Hsm