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

  • Home
  • SEARCH
  • 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 6359211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:29:18+00:00 2026-05-24T23:29:18+00:00

I have a UISlider that has two text boxes attached to it. Think of

  • 0

I have a UISlider that has two text boxes attached to it. Think of it like a tip calculator. Think about a receipt: it has a spot for you to put the tip, and then the final value. Let’s add a slider into the mix.

So now we have two text fields (tip percentage and tip amount) and the slider. When the slider moves it calls a method that updates the two text boxes according to the value that the person has selected with the slider.

[self.slider addTarget:self 
                    action:@selector(sliderValueChanged:) 
          forControlEvents:UIControlEventValueChanged];

-(void)sliderValueChanged:(id)sender
{
    tipPercent.text = [NSString stringWithFormat:@"%d", (int)slider.value];
    tipPercentDbl = (int)slider.value;//tipPercent as Dbl
    tipDbl = (totalDbl * (tipPercentDbl/100));//tip as Dbl
    tip.text = [NSString stringWithFormat:@"%.2f", tipDbl];
    tipPercent.text = [NSString stringWithFormat:@"%.0f", tipPercentDbl];
    totalWithTipDbl = (totalDbl+tipDbl);
    totalWithTip.text = [NSString stringWithFormat:@"%.2f", totalWithTipDbl];
}

This works perfectly. What I want to do now (and am having trouble figuring it out) is how to change the value when the text fields are changed. i.e. someone manually enters in their own tip, how to update the slider and the tip percentage; or if someone manually enters in a tip percentage, how to update the slider and the tip value.

What would be the best way to do this?

  • 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-24T23:29:19+00:00Added an answer on May 24, 2026 at 11:29 pm

    This is fairly easy. I don’t know all the variables you used, so substitute your own when you try the code. When the keyboard resigns, call the method:

    - (void)updateTheSliderAndTipPercentage; {
      float percentage = tipTheyEntered / totalCost;
      [slider setValue:percentage animated:YES];
      percentage *= 100; // This is if you want the percentage in [0,100].
      tipPercent.text = [NSString stringWithFormat:@"%f", percentage];
    }
    

    EDIT: In order to know when you call this method, simple check:

    - (BOOL)textFieldShouldReturn:(UITextField *)textField; {
      if(textField == tipTheyEnteredTextField){
        [self updateTheSliderAndTipPercentage];
      }
    }
    

    Hope that helps!

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

Sidebar

Related Questions

I want to use a vertical UISlider . I have no idea about how,
I have a question that is driving me crazy. It is all about updating,
I am using the jQuery UISlider. I have it set up so that upon
I have a UITextView that is supposed to have one line of text. The
I have a custom UITableViewCell that contains a UISlider control and a UILabel which
I want to rotate a image with UIslider control. I have done that with
I have a UISlider as part of a view that is loaded into a
For example, I have a UISlider that calls - (IBAction)sliderMoved:(id)sender , which performs some
I have a UISlider that I want to update a UITextField for the value
I have a UISlider that I wan't to have a custom look for. I

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.