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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:56:00+00:00 2026-05-28T00:56:00+00:00

So I have a UIView object (called gauge) on the right hand side that

  • 0

So I have a UIView object (called gauge) on the right hand side that is a vertical bar. I have another label to the left of that bar that I want to display different text at different levels of the vertical bar (navLabel). I want this label to look like it is pinned to some distance (like 10 px) to my vertical bar. My label is left justified. I do this in the different methods where I need to update the label:

        CGSize labelSize = [navLabel.text sizeWithFont:[UIFont fontWithName:@"Arial" size:17.0]];
        CGRect newFrame = CGRectMake(gauge.frame.origin.x - 10 - labelSize.width, FIRST_HEIGHT, navLabel.frame.size.width, navLabel.frame.size.height);
        [UIView animateWithDuration:0.5 animations:^{
            self.navLabel.frame = newFrame;
        }];

In my different methods, I just change to the appropriate height (i.e. #define FIRST_HEIGHT).

My label ends up in the places I want, but the animation looks funny. For example, if my first label was @"label 1", and my second label was @"my much much much longer label", what happens is the label goes to the correct height, but because the labels are different sizes, you see the x-animation as well which makes it look funny. I only want animation in the y-direction. How can I accomplish that?

I also tried right justified, but then my label does not end up the correct distance to my gauge object. It ends up crossing it many times and I’m not sure why that happens.

  • 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-28T00:56:00+00:00Added an answer on May 28, 2026 at 12:56 am

    It’s not clear that this is the behavior you want, but why not just set navLabel.frame to have the correct (new) x-coordinate as its origin before animating, then animate to the new frame that has the correct origin with the new height offset?

    Or, set up two animations using these two frames, one that animates the y-direction first and the second that animates the x-direction to the new x-coordinate of the frame origin. Or vice versa.

    // This version simply sets the correct origin (and the correct new width), then animates the y-direction
    CGSize labelSize = [navLabel.text sizeWithFont:[UIFont fontWithName:@"Arial" size:17.0]];
    self.navLabel.frame = CGRectMake(gauge.frame.origin.x-10-labelSize.width, self.navLabel.frame.origin.y,labelSize.width,navLabel.frame.size.height);
    // now navLabel's frame has the correct new width (and origin x-coord)
    CGRect newFrame = CGRectMake(self.navLabel.origin.x, FIRST_HEIGHT, navLabel.frame.size.width, navLabel.frame.size.height);
    // now this animation will cause movement only in the y-direction 
    [UIView animateWithDuration:0.5 animations:^{
            self.navLabel.frame = newFrame;
        }];
    
    // This version animates the change in the frame in the x-direction first, then does what it did before
    CGSize labelSize = [navLabel.text sizeWithFont:[UIFont fontWithName:@"Arial" size:17.0]];
    CGRect newFrame = CGRectMake(gauge.frame.origin.x-10-labelSize.width, self.navLabel.frame.origin.y,labelSize.width,navLabel.frame.size.height);
    // this animation will cause movement in the x-direction 
    [UIView animateWithDuration:0.5 animations:^{
            self.navLabel.frame = newFrame;
        }];
    // now navLabel's frame has the correct new width (and origin x-coord), so set the new y-coord
    CGRect newFrame = CGRectMake(self.navLabel.origin.x, FIRST_HEIGHT, navLabel.frame.size.width, navLabel.frame.size.height);
    // now this animation will cause movement only in the y-direction 
    [UIView animateWithDuration:0.5 animations:^{
            self.navLabel.frame = newFrame;
        }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIView subclass that draws itself when -drawRect: is called. It only
I have a little UIView object, CircleColorView.m, that simply creates a view with a
I have a UIView object that can be dragged around using UIPanGestureRecognizer, but I
I have a UIView object X that is contained in an UIView object A.
In my program, I have a class called Object, which inherits from UIView. I
I have a UIView object that rotates using CALayer 's transform: // Create uiview
I have a UIView that updates based on data in a certain object. I'd
I have subclassed UIView object inside a uiscrollview which displays a pdf page. I
I have a UIView that will eventually contain about 2 screens worth of information.
I have a UIView with a navigation bar. How can I hide the navigation

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.