how to force horizontal scrolling only on UITextView - iphone

I have a UITextView with contentSize property set to a very large value 1000, the width of the UITextView is 200, scrolling is enabled, horizontal bouncing is enabled and vertical bouncing is disabled but this UITextView still scrolls vertically on large text.
how can I force horizontal scrolling on it ?
p.s. the solution here does't work.

UITextView is a subclass of - UIScrollView. So you can use ScrollViewDelegate method for disabling this.
Use -
- (void)scrollViewDidScroll:(id)aScrollView
{
[aScrollView setContentOffset:CGPointMake([scrollView contentOffset].x, 0.0)];
}

I have tried many different ways to have a horizontal scrolling functionality to work as expected, but non of these methods worked for me, so I created a UIScrollView and added a UILabel as a subview in the scroll view, and setting the frame's width of the label dynamically according to its text and the text font, after that I set the contentSize of the scroll view to be equal to the label's new frame width & height. Using this method you will have a horizontal scrolling text.

Using JAHelia's advice, this worked for me:
self.dishNameLabel.text = #"Here is some very longgggg text to test with";
float width = ceil([self.dishNameLabel.text sizeWithAttributes:#{NSFontAttributeName: [UIFont fontWithName:#"WorkSans-SemiBold" size:15.0]}].width);
self.dishNameLabel.frame = CGRectMake(self.dishNameLabel.frame.origin.x, self.dishNameLabel.frame.origin.y, width, self.dishNameLabel.frame.size.height);
self.dishNameScrollView.contentSize = CGSizeMake( width, self.dishNameScrollView.frame.size.height);
Of course, you will have to replace your text and font with your respective specs

Related

UItextview cursor position

I've a UITextview with these constraints:
Align Center x,y and width and height equals.
When I click the UItextview for the first time the cursor is like:
When I write inside:
When I delete characters:
what happened?
Your UITextView height is too small and it's contentSize height is bigger than it's frame height. A UITextView is a subclass of an UIScrollView so it's content is scrolling, this is what's happening in your case.
This is cause by textContainerInset.
you can add the follow code to solve:
tetxView.textContainerInset = UIEdgeInsetsZero;
other strange issue maybe you can solve by this:
textView.textContainer.lineFragmentPadding = 0;

Disable right scrolling in uiscrollview in iphone

How can i disable left or right scrolling in scrollview in iPhone?
can any one give the code..
CGSize scrollableSize = CGSizeMake(320, myScrollableHeight);
[myScrollView setContentSize:scrollableSize];
You have to set the contentSize property of the UIScrollView. Like, if your UIScrollView is 320 pixels wide (the width of the screen), then you could do this
The UIScrollView will then only scroll vertically.
set your scrolview width 320. It will
like
[self.scrolview setFrame:CGRectMake(self.scrolview.frame.origin.x,self.scrolview.frame.origin.y,320,self.scrolview.frame.size.height)];

How can I calculate the contentsize of UItextView in which the text are dynamically added………

I ve an UIScrollview ,in which I ve placed UIImageView and UITextView..Here I add the data to the UITextView dynamically…I want to scroll both the image and the text at the same time .It works fine..I ve assigned the contentsize of the UITextView to the contentsize of the UIScrollView…..Since I am adding the data dynamically I can't use the standard values..Any samples to find the contentsize of UITextView????
UITextView is a subclass of UIScrollView. So you can directly use the contentSize method,
CGSize _contentSize = textView.contentSize;
float _height = _contentSize.height;

Image scroller problem

hello every buddy
i want to make horizontal image scroller at bottom view and in the back of side big Image View. i don't know how to make image horizontal scroll.
Place the image view inside a scroll view whose horizontal content size is greater than its frame width, i.e.
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = CGRectMake(0, 0, 100, 100);
scrollView.contentSize = CGSizeMake(300, 100);
[scrollView addSubview:imageView];
You should use contentSize property of the UIScrollView to set its content size according to your requirement and then set the property showsHorizontalScrollIndicator to YES and showsVerticalScrollIndicator to NO . But you don't require to set these two if you set frame and content size properly. Like if _myScrollView.frame.height and _myScrollView.contentSize.height is same then you don't need to set horizontal and vertical scroll. Its vertical scroll will automatically be disabled.
you can use scroll view with page control for a horizontal slideshow. follow the tutorial it might help you
http://www.edumobile.org/iphone/iphone-programming-tutorials/pagecontrol-example-in-iphone/

How to enforce horizontal scrolling on UITextView?

I have a UITextView and I would like to only allow it to be scrollable horizontally only.
Basically when the UITextView word-wraps I want the user to have to scroll horizontally to be able to view the rest of the contents.
You can set the content size of the text view to the height of the view. Just make sure the width of the content extends past the width of the textView's frame or else it won't scroll.
// UITextView* myTextView: gets declared somewhere...
// The text view (subclass of a UIScrollView) won't go past its content size
[myTextView setContentSize:CGSizeMake(width, myTextView.frame.size.height)];
// Just in case, if you don't want your user bouncing the view up/down
[myTextView setAlwaysBounceVertical:NO];
I hope that's what you were looking for.
The solution is to turn off all the scroll options on the UITextView itself, then embed it in another UIScrollView. You can get actual code by searching on this term "DualScrollTextView" in google. You cannot force changes to contentSize to accomplish this - many have tried.
This worked for me:
self.dishNameLabel.text = #"Here is some very longgggg text to test with";
float width = ceil([self.dishNameLabel.text sizeWithAttributes:#{NSFontAttributeName: [UIFont fontWithName:#"WorkSans-SemiBold" size:15.0]}].width);
self.dishNameLabel.frame = CGRectMake(self.dishNameLabel.frame.origin.x, self.dishNameLabel.frame.origin.y, width, self.dishNameLabel.frame.size.height);
self.dishNameScrollView.contentSize = CGSizeMake( width, self.dishNameScrollView.frame.size.height);
Of course, you will have to replace your text and font with your respective specs