Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:28:58+00:00 2026-05-27T09:28:58+00:00

I have two little problems with my UIScrollView. I managed to create scroll view,

  • 0

I have two little problems with my UIScrollView.

I managed to create scroll view, which is similar to the picker view except that it’s horizontal.

The problem n.1 is – How do I get the number which the user tapped?

The problem n.2 is – How do I make the scrollview to go round and round – never-ending?

A question – Is it possible to make some “selection indicator”?

Here is my code:

numberArray = [NSArray arrayWithObjects:@”1″, @”2″, @”3″, @”4″, @”5″,
@”6″, @”7″, @”8″, @”9″, @”10″, @”11″, @”12″, @”13″, @”14″, @”15″,
@”16″, @”17″, @”18″, @”19″, @”20″, @”21″, @”22″, @”23″, @”24″, @”25″,
@”26″, @”27″, @”28″, @”29″, @”30″, @”31″, @”32″, @”33″, @”34″, @”35″,
@”36″, @”37″, @”38″, @”39″, @”40″, @”41″, @”42″, @”43″, @”44″, @”45″,
@”46″, @”47″, @”48″, @”49″, @”50″, @”51″, @”52″, @”53″, @”54″, @”55″,
@”56″, @”57″, @”58″, @”59″, @”60″, @”61″, @”62″, @”63″, @”64″, @”65″,
@”66″, @”67″, @”68″, @”69″, @”70″, @”71″, @”72″, @”73″, @”74″, @”75″,
@”76″, @”77″, @”78″, @”79″, @”80″, @”81″, @”82″, @”83″, @”84″, @”85″,
@”86″, @”87″, @”88″, @”89″, @”90″, @”91″, @”92″, @”93″, @”94″, @”95″,
@”96″, @”97″, @”98″, @”99″, @”100″, nil];

masterDividerView = [[UIView alloc] initWithFrame:CGRectMake(0, 480, 320, 44)];

morePeople = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 53)];
morePeople.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
morePeople.delegate = self;
[morePeople setBackgroundColor:[UIColor whiteColor]];

[morePeople setCanCancelContentTouches:NO];

morePeople.showsHorizontalScrollIndicator = NO;
morePeople.showsVerticalScrollIndicator = NO;
morePeople.clipsToBounds = NO;
morePeople.scrollEnabled = YES;
morePeople.pagingEnabled = NO;

NSUInteger nimages = 0;
NSInteger tot=0;
CGFloat cx = 0;
for (; ; nimages++) {
    NSString *label = [numberArray objectAtIndex:nimages];

    if (tot==99) {
        break;
    }
    if (99==nimages) {
        nimages=0;
    }

    UILabel *labelView = [[UILabel alloc] init];
    labelView.text = label;
    labelView.lineBreakMode = UILineBreakModeWordWrap;
    labelView.numberOfLines = 0;
    [labelView sizeToFit];
    labelView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];


    CGRect rect = labelView.frame;
    rect.size.height = 53;
    rect.size.width = 40;
    rect.origin.x = cx;
    rect.origin.y = 0;

    labelView.frame = rect;

    [morePeople addSubview:labelView];

    cx += labelView.frame.size.width+5;
    tot++;
}


self.pageControl.numberOfPages = nimages;
[morePeople setContentSize:CGSizeMake(cx, [morePeople bounds].size.height)];

[masterDividerView addSubview:morePeople];
[self.view addSubview:masterDividerView];

If anybody knows a good solution to this, I would be very happy!!!! :))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:28:59+00:00Added an answer on May 27, 2026 at 9:28 am

    Your question is too wide to make a detailed answer, but yes, everything of what you’re talking about can be solved in a quite easy way.

    The problem n.1 is – How do I get the number which the user tapped?

    If you mean to know what element is chosen by your UIScrollView at the moment, then it’s not a problem: UIScrollView always knows its position (contentOffset), which gives you the easy possibility to define, which object is chosen (which object you’re working with) now.

    If you mean to know when the user tapped by his finger one of the elements of your “picker view” (UIScrollView), then I would say that the answer to this depends on how you actually represent your data (like if you see one or several elements of your scrollView at a time on your screen). But in any case you can easily solve this by using UITapGestureRecognizer. Smth like:

    // add gesture recognizers to the scroll view 
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [singleTap setNumberOfTapsRequired:1];
    [self.yourScrollView addGestureRecognizer:singleTap];
    [singleTap release];
    

    And then to scroll it programmatically in your selector you do smth like:

    - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
    {
        CGPoint pointOfTouch = [gestureRecognizer locationInView:self.view];
        if ( (pointOfTouch.x > self.rightArrowMin) && (pointOfTouch.x < self.rightArrowMax) ) {
            [scrollView setContentOffset:CGPointMake(lastOffset + self.lengthOfLabel, 0) animated:YES];
        } else if ( (pointOfTouch.x > self.leftArrowMin) && (pointOfTouch.x < self.leftArrowMax) ) {
            [scrollView setContentOffset:CGPointMake(lastOffset - self.lengthOfLabel, 0) animated:YES];
        }
    }
    

    The problem n.2 is – How do I make the scrollview to go round and round – never-ending?

    It can be solved if you know the algorithm of calculating the next/previous or random element in the sequence of elements of your scrollView.
    Basically, I solved this same thing for myself in one of my projects (free app “IJCAI11” in the appStore, there you can see at the work of a datePicker in the details of any chosen conference’s day: there is applied the algorithm of infinite scrolling view, the limits I applied later only from design point of view).
    The scheme I use there is simple, though perhaps a bit weird (before reading ahead, note that in my case I see only one element of scrollView on the screen, when the scrollView is in nonscrolling state):

    1. I create the UIScrollView with 3 (in case you see more than 1 element at a time this can be like 5, 7, …, 2N+1 according to your very case) labels;
    2. Make the second (central) label active.
    3. Assign proper value to all 3 (2N+1) labels. On this step your second (central) label will contain data of (will show) the default value.
    4. When user scrolls one step left/right (to the position M_pos), you do it in a standard way, since your neighboring to central labels contain correct data (M).
    5. Then you take this new active value (M) and apply it for your central label (this is gonna be behind the scene, therefore the user wont see this on the screen), then you recalculate ALL the other labels properly ( …, M-1, M, M+1, …), including your M_pos position(!).
    6. With “animated:NO” mode you shift your scrollView to your central position. In this case user doesn’t see anything, when in fact his scrollView was moved from position M_pos to the central position. All neighboring labels are already recalculated and you are ready to repeat the point 4 any number of times you wish, making a strong feeling for user, that he works with the scrollView with a huge number of elements (whereas in practice your just work with 3 (2N+1) labels, changing their content after every movement).

    A question – Is it possible to make some “selection indicator”?

    If I understand this question correctly, then just consider the View/Subview thing and in particular the function addSubview of View class 😉

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got two little problems with this interface. The worse one is that I have
I have two tiny little problems; 1 . I want to add a previous
I'm getting a little stuck with two entwined problems. First, I want to have
I have this little problem. My client wanted two distinct swf on a web
I've been working on an application for a little over two years and have
I have two applications written in Java that communicate with each other using XML
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have a little logging app (written in wxPython) that receives data from a
I have a little app that downloads stock prices and was working perfectly (for
I have a question here that looks a little like some of the ones

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.