UIScrollView

Discussion in 'iOS Development' started by wearmaize, Apr 23, 2009.

  1. wearmaize

    wearmaize Active Member

    Joined:
    Feb 13, 2008
    Messages:
    2,442
    Likes Received:
    13
    Device:
    iPhone 4S (Black)
    How do you implement UIScrollView? Can anyone give me a quick guide? I have a lot of text, and I want to have it on one page and be able to scroll up and down (not left to right). Thanks!

    Assume I know nothing about developing right now. That's because I don't.

    Please Register or Log in to view images

  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Just set the contentView's frame to be larger than the scroller's frame. Instant scrolling.

    Oh also, set scrolling enabled. You'll see, UIScrollViews are super easy (that includes scrolling, zooming, and paging).
  3. wearmaize

    wearmaize Active Member

    Joined:
    Feb 13, 2008
    Messages:
    2,442
    Likes Received:
    13
    Device:
    iPhone 4S (Black)
    Thanks for the quick reply. Can you please explain how to do that? This is my first time coding anything at all.

    Please Register or Log in to view images

  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    It's all in the docs.
    Code:
    UIScrollView *yourScroller = [[UIScrollView alloc] initWithFrame:theFrameYouWantYourScrollViewToHave];
    yourScroller.alwaysBounceHorizontal = bodyScroller.alwaysBounceVertical = YES;
    yourScroller.backgroundColor = theColoryouWantTheBackgroundToBe;
    yourScroller.clipsToBounds = YES;
    yourScroller.contentSize = theViewYouWantToScroll.frame.size; //For example.
    yourScroller.delegate = self;
    yourScroller.scrollEnabled = YES;
    yourScroller.indicatorStyle = UIScrollViewIndicatorStyleWhite; //Or, whatever
    [yourScroller addSubview:theViewYouWantToScroll];
  5. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Create the new UIView, whether it be in IB or through code, and have the width and height larger than the UIScrollView's frame. I thought Skylar explained it pretty well.





    [EDIT: Post undeleted--Skylar]
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    If you're doing this in Interface Builder, then create a new UIView object. set its class identity to UIScrollView. Now, go to its attributes and set all these variables there.

    Either way works.
  7. wearmaize

    wearmaize Active Member

    Joined:
    Feb 13, 2008
    Messages:
    2,442
    Likes Received:
    13
    Device:
    iPhone 4S (Black)
    Here, let me be a little more specific: I am clueless.

    Please Register or Log in to view images


    OK, first of all, I created a View in my current MainWindow.xib file. When I dragged it over the window, it became pretty small, and it covered all of the text that was there. So, I made it invisible (in attributes). In attributes, there are the options: "Mode" "Alpha" "Tag" "Drawing" and "Interaction." I'm sorry to bother you again, but where do I put the text that you posted in the 4th post? And do I need to change any of the code to match my project? Thanks again!

    Please Register or Log in to view images

Share This Page