Reputation: 1943
I want to display one paragraph in UITextView
. I'm able to put the content of paragraph in Text view, but I'm unable to scroll UITextView
(Some of the content is not visible as it's not scrolling).
What I'm trying to do is:
CGRect frame = CGRectMake(0, 0, 320, 480);
//allocate view
self.view = [[UIView alloc]initWithFrame:frame];textview = [[UITextView alloc]initWithFrame:CGRectMake(30, 200, 275, 400)];
[textview setFont:[UIFont fontWithName:@"Arial" size:12]];
[textview setScrollEnabled:YES];
[textview setUserInteractionEnabled:NO];
[textview setBackgroundColor:[UIColor clearColor]];
//[textview setText:@"Hi,I'm working fine with this space"];
[self.view addSubview:textview];
In this case, scrolling is enabled. Can any one tell me why it's not scrolling?
Upvotes: 13
Views: 32658
Reputation: 719
I have a ViewController that only has a text view with about 5 pages of text.
Here is what I did in Swift 4.0:
Swift 4.0
textForPrivacyPolicy.showsVerticalScrollIndicator = true
textForPrivacyPolicy.isEditable = false
textForPrivacyPolicy.isScrollEnabled = true
textForPrivacyPolicy.scrollRangeToVisible(NSMakeRange(0, 0))
textForPrivacyPolicy.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
Upvotes: 4
Reputation: 3523
bapi rout , There is a property for the user interaction with textView. You have set it to No. If you want to perform scroll on TextView, You have to enable this property.
[textview setUserInteractionEnabled:YES];
This will help you.
Upvotes: 0
Reputation: 51
I had the same issue and I had setscrollable and userinteractionenabled to TRUE. It turned out to be a problem with Constraints. In order to fix this, click on your view controller in ur storyboard (the battery icon on top right), then go to "Editor"->"Resolve Auto Layout Issues"->"Add Missing Constraints In ". Fixed the issue for me!
Upvotes: 0
Reputation: 8256
Add this line : [textview setUserInteractionEnabled:YES];
in place of this:
[textview setUserInteractionEnabled:NO];
Upvotes: 2
Reputation: 825
set [textview setUserInteractionEnabled:TRUE];
and I think you dont want to keyboard to pop up then you can hide the keyboard by implementing the uitextview delegate methode -(void)textViewDidBeginEditing:(UITextView *)textView{[textView resignFirstResponder];
Upvotes: 20
Reputation: 6587
Paste this code
CGRect frame = CGRectMake(0, 0, 320, 480);
//allocate view
self.view = [[UIView alloc]initWithFrame:frame];textview = [[UITextView alloc]initWithFrame:CGRectMake(30, 200, 275, 400)];
[textview setFont:[UIFont fontWithName:@"Arial" size:12]];
[textview setScrollEnabled:YES];
[textview setUserInteractionEnabled:YES];
[textview setBackgroundColor:[UIColor clearColor]];
//[textview setText:@"Hi,I'm working fine with this space"];
[self.view addSubview:textview];
Upvotes: 2
Reputation: 20541
set YES
for setUserInteractionEnabled
property of UITextView
set this line
[textview setUserInteractionEnabled:YES];
instead of
[textview setUserInteractionEnabled:NO];
Upvotes: 7