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 6015707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:52:30+00:00 2026-05-23T02:52:30+00:00

I am trying to implement a simple quiz app on the iphone in the

  • 0

I am trying to implement a simple quiz app on the iphone in the spirit of learning, part of this app is a timer.

I want my timer to count down from 10 to 0. I had a simple NSTimer that repeats and calls a method every second and in this method I update a label which displays the remaining time, which works nicely.

Now instead of displaying the timer using a label I wanted to use a graphical progress bar, so I created ten images, one full in length (representing 10), the next 9/10 of the size and so on, and in my repeating timer method instead of updating a label I update a UIImage with the appropriate image so over time the progress bar gets smaller and smaller.

My problem is that due to the way I have implemented the progress bar, it doesn’t look very smooth when it updates every second. Is there another way I should approach developing this kind of functionality? I have heard that you could use a stretchable image to get a smoother effect but I couldn’t see any good examples of that.

Any advice and code samples welcome, just trying to learn here.

  • 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-23T02:52:31+00:00Added an answer on May 23, 2026 at 2:52 am

    After investigating a few options I have decided to use a UIProgressView (suggested by sudo in comments) coupled with a NSTimer which updates the progress ten times a second for ten seconds, I used this solution because:

    1. It is a standard element provided by apple.
    2. This option doesn’t have the overhead of creating and loading 100 images (as suggested by Krypton in the comments).
    3. By the NSTimer I can add a check to the function updateProgressBar to add some feedback to the user when the timer is reaching low, e.e. vibrate for the last three seconds etc (using animation I don’t think I would have that option).

    Using the code below assume I have a UIProgressView variable named ‘progressView’, an NSTimer named ‘timer’ and a floating point variable named ‘time’, then:

    -(void)updateProgressBar
    {
        if(time <= 0.0f)
        {
            //Invalidate timer when time reaches 0
            [timer invalidate];
        }
        else
        {
            time -= 0.01;
            progressView.progress = time;
        }
    }
    
    -(void)animateProgressView2
    {
        progressView.progress = 1;
        time = 1;
        timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f
                                                 target: self
                                               selector: @selector(updateProgressBar)
                                               userInfo: nil
                                                repeats: YES];
    }
    

    Another way I investigated (after seeing Disco’s comments) but decided against was to use animation. In this instance I created two png images, named ‘redbar.png’ and ‘greenbar.png’, the idea bring they would be placed over each other (the green bar being on top/in the foreground), and over the duration of the animation the green bar shrinks, revealing the red bar in the background.

    UIImage *green= [UIImage imageNamed:@"greenbar.png"];
    UIImage *red= [UIImage imageNamed:@"redbar.png"];
    
    redBar.image = red; // allocate the red image to the UIImageView
    redBar.frame = CGRectMake(20,250,220,30);// set the size of the red image
    
    greenBar.image = green; // allocate the green image to the UIImageView
    greenBar.frame = CGRectMake(20,250,220,30);//set the size of the green image
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:10]; //the time you want the animation to last for
    [UIView setAnimationDidStopSelector:@selector(animationFinished)];//the method to be called once the animation is finished
        //at the end of the animation we want the greenBar frame to disappear
        greenBar.frame = CGRectMake(20,250,0,30);
    [UIView commitAnimations];
    

    An ideal solution would be to combine the UIProgressView and the UIAnimation block, but this is not currently an option (see this question animate a UIProgressView's change).

    Hope this helps someone in the future.

    EDIT::

    It appears the ideal solution I mention above is now available in iOS5, taken from the apple reference site:

    setProgress:animated:
    Adjusts the current progress shown by the receiver, optionally animating the change.

    • (void)setProgress:(float)progress animated:(BOOL)animated
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a simple plist example from Beginning iPhone 3 Development
I am trying to implement simple xhr abstraction, and am getting this warning when
I am trying to implement a simple TTURLRequest in my app. I'm pretty new
I want to implement a simple VersionedModel base model class for my app engine
I'm trying to implement this simple example of how to synchronize threads using pthread
I'm trying to implement a simple char count of an UITextView while the user
I am trying to implement a search algorithm in my simple datastructure. However, this
I'm trying to implement simple Event Bus I started like this: public class RegistrationData
I am trying to implement a simple android app with forms inside it. I
I'm new to Flex SDK and trying to implement a simple project using Doug

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.