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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:42:12+00:00 2026-05-27T11:42:12+00:00

How can I make a text field (or something that looks similar) with a

  • 0

How can I make a text field (or something that looks similar) with a number in it, which you can increase or decrease by touching it and swiping your finger up (increase) or down (decrease).

How it would work: There is a texfield with 0.0 on it. You touch it, and move your finger down. Then you see the value decrease as you move your finger further. When you stop moving your finger, the value doesn’t change.

How could this be done in Objective-C?

  • 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-27T11:42:12+00:00Added an answer on May 27, 2026 at 11:42 am

    This answer is quite big, so I decided to put some sample code on github.

    To cater for multiple labels, we’re first going to subclass UILabel, to add a property called dragging. We’re gong to call the class DragLabel.

    DragLabel.h

    #import <Foundation/Foundation.h>
    
    @interface DragLabel : UILabel {
        BOOL dragging;
    }
    
    @property (assign) BOOL dragging;
    
    @end
    

    DragLabel.m

    #import "DragLabel.h"
    
    @implementation DragLabel
    @synthesize dragging;
    
    @end
    

    Interface Builder

    Now you need to drag three labels into the view in IB, and change all their classes to DragLabel. Make sure you do this before creating the outlets.

    Class Change in IB

    After doing this, hook all the outlets up to your .m and .h. In my instance, I gave them names of label1, label2 and label3.


    Now we have our label class and interface set up, its time to write the code for the view controller.

    Your Controller.h should look like this. I called it DragViewController.h

    #import <UIKit/UIKit.h>
    #import "DragLabel.h"
    
    @interface DragViewController : UIViewController {
        DragLabel *label1;
        DragLabel *label2;
        DragLabel *label3;
    
        NSArray *draglabels;        
    }
    
    @property (nonatomic, retain) IBOutlet DragLabel *label1;
    @property (nonatomic, retain) IBOutlet DragLabel *label2;
    @property (nonatomic, retain) IBOutlet DragLabel *label3;
    

    Your Controller.m should look like this. I called it DragViewController.m

    #import "DragViewController.h"
    
    @implementation DragViewController
    @synthesize label1;
    @synthesize label2;
    @synthesize label3;
    
    - (void)dealloc
    {
        [label1 release];
        [label2 release];
        [label3 release];
        [draglabels release];
        [super dealloc];
    }
    
    - (void)viewDidLoad
    {
        draglabels = [[NSArray alloc] initWithObjects:label1, label2, label3, nil];
        for (DragLabel *label in draglabels) {
            label.dragging = NO;
        }
    
        [super viewDidLoad];
    }
    
    - (void)movedLabel:(DragLabel *)label touchloc:(CGPoint)touchloc {
        float val = (label.center.y - touchloc.y)/10;
        label.text = [NSString stringWithFormat:@"%g",val];
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        CGPoint touchloc = [[touches anyObject] locationInView:self.view];
        for (DragLabel *label in draglabels) {
            if (CGRectContainsPoint(label.frame, touchloc)) {
                label.dragging = YES;
                [self movedLabel:label touchloc:touchloc];
            }
        }
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        for (DragLabel *label in draglabels) {
            if (label.dragging) {
                CGPoint touchloc = [[touches anyObject] locationInView:self.view];
                [self movedLabel:label touchloc:touchloc];
            }
        }
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        for (DragLabel *label in draglabels) {
            label.dragging = NO;
        }
    }
    
    - (void)viewDidUnload
    {
        [self setLabel1:nil];
        [self setLabel2:nil];
        [self setLabel3:nil];
        [super viewDidUnload];
    }
    
    @end
    

    One last thing

    To adjust the scale so it ranges from 0 to 1, only when the user drags above the label, re-implement movedLabel like this:

    - (void)movedLabel:(DragLabel *)label touchloc:(CGPoint)touchloc {
        float ydif = label.center.y-touchloc.y;
        float maxheight = 100;
        if (ydif > 0) {
            if (ydif <= maxheight) label.text = [NSString stringWithFormat:@"%g",ydif/maxheight];
            else label.text = [NSString stringWithFormat:@"%g",maxheight];
        }
        else label.text = @"0.0";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some kind of text-parser for ASP.NET that can make HTML from
In the following case, how can I make it such that the text generated
So i have a field that datatype is a text which is feed into
In QMessageBox how can I make the title text bold? Here is the sample
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand
In MS Visual Studio, you can hold down the Alt key and make text
How can I make my strings and text attributes bold in my actionscript code?
How can I make a list with pictures and summary (the text under the
How can I make my <div> elements grow (and the content changes text size
when a text box is on focus, how can I make a listen to

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.