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)];
Related
I have a view controller with a table view. The UITableViewCell width is set to 320 in IB. Now, I want to use the view controller in iPad by adding it to a superview. The superview's width is bigger than 320. The table view shows on the superview. The problem is that it only occupy 320. How can I change the cell width to occupy whole superview's width? Thanks.
Hey you need to create a custom UITableViewCell. Than you can overwrite the function
- (void) layoutSubviews
{
[dateLabel setFrame:CGRectMake(10.f, 16.f, 80.f, 12.f)];
[textLabel setFrame:CGRectMake(106.f, 16.f, self.frame.size.width-105.f + 1.f, 12.f)];
}
In that function the self.frame.size.width is the actual one.
And it works with rotation of the device, too.
Hello friends i am very new to ios.
I am setting scroll size in view did load as
scrollView.frame=CGRectMake(0, 0, 320, 460);
[scrollView setContentSize:CGSizeMake(320,500)];
now i want to scroll my frame up on clicking on button.
scrollView.frame=CGRectMake(0,-100, 320,550);
my frame moves up but after this my scroll view is disabled i also tried using scrollview enabled but it also not works.
please suggest me Thanks in advance for your ans.
Because second time you're setting
scrollView.frame=CGRectMake(0,-100, 320,550);
in which 550 is height of scrollView and it is greater than its content height as you have set
[scrollView setContentSize:CGSizeMake(320,500)];
If you want to move your scrollView frame up on clicking on button then just decrease its Y co-ordinate dont increase its height. For vertical scrolling content height should be greater than frame height.
So second time set frame like this -
scrollView.frame=CGRectMake(0,-100, 320, 460);
You set [scrollView setContentOffset:animated:] instead of setting frame to scroll. Ref
In your case, you can probably do
[scrollView setContentOffset:CGPointMake(0, 100) animated:YES];
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
Within my view I create a scrollview with a width of 320 and a height of 70.
Responding to the user touching a button, I expand the scrollview, so it is 380(h) x 320(w) in size.
The code for this is shown below:
CGRect scrollviewFrame = CGRectMake(0, 30, 320, 380);
[scrollView setFrame:scrollviewFrame];
[self layoutScrollImages:YES];
CGSize srect = CGSizeMake([scrollView bounds].size.width, (kNumImages * (kScrollObjHeight + 10)));
[scrollView setContentSize:srect];
The constants mentioned in the above snippet are defined as:
const CGFloat kScrollObjHeight = 80;
const NSUInteger kNumImages = 100;
As I debug this project, I can see that srect is 320 (w) x 8000 (h) in size; however my issue is the scrollable area (where the user can actually touch to scroll the scrollview) remains the same as when it was it's original size.
I'm obviously missing something, does anyone know what it is?
have created a sample project to illustrate the issue I am having, it is available here: http://dl.dropbox.com/u/9930498/ScrollViewTest.zip
The problem in your sample is you have a very odd structure for loading your views. As such the view you're adding to the DetailScrollView instance is the root view of the DetailScrollView.xib, not the scrollview itself, which I believe is what you were expecting.
Fastest way to fix your problem is to adjust the root view in DetailScrollView.xib to autoresize width and height.
A UIView cannot respond to touches that are outside of the bounds of its superview. In your example, it appears that you expand the scroll view, but the scroll view's parent is still only 100 units high.
You should imagine the scrollView as a window, where by the window I mean the frame of the scrollView, which is also the coordinates that the scrollView detects your touches. By setting the contentView as 320 (w) x 8000 (h) you only change the content of the scroll view, which is the complete area behind that window.
By expanding content view, the scrollView can scroll a broader area, but in order to detect touches in a bigger rect, you should change frame of the scroll view.
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/