Reputation: 175
I have a UITextView , i want show its' text in horizontal, my UITextView has a static width
[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 161, 23)];
so when the length of UITextView's text is greater than 23, i need UITextView horizontal scrolling , please help me...
Upvotes: 3
Views: 3970
Reputation:
- (void)viewDidLoad {
// We restrict the horizontal scrolling here.
self.textView.contentSize = self.textView.frame.size;
}
Implement this text view delegate method.
Now when the characters entered becomes greater than 23, we set the content size of the text view to a higher value so that horizontal scrolling gets enabled automatically.
- (void) textViewDidChange:(UITextView *) tView {
if (tView.text.length > 23) {
// Set some higher width of the text view content size.
tView.contentSize = CGSizeMake(200.0f, tView.frame.size.height);
}
}
Upvotes: 1
Reputation: 4617
If you are using interface builder then just check the property.
show horizontal scrolling.
by default this property is not enable
Upvotes: 0
Reputation: 2719
put this code after initializing
[txt setContentOffset:CGPointMake(give_high_value_here_than_content, y)];
Good luck
Upvotes: 1
Reputation: 3675
mscrollview.contentSize = CGSizeMake(180,30);
mscrollview.showsHorizontalScrollIndicator = YES;
Use this 2 lines.
Upvotes: 0