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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:20:58+00:00 2026-06-10T12:20:58+00:00

I made two instances of UILabel and added them to my ViewController ‘s view.

  • 0

I made two instances of UILabel and added them to my ViewController‘s view.
And then I changed the anchorPoint of each from 0.5 to 1.0 (x and y).

Next, I reset the frame of uiLabel2 to its frame I created it with: (100,100,100,20).

When I run the app, uiLabel1 and uiLabel2 show at different positions. Why?

UILabel *uiLabel1 = [[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 20)] autorelease];
uiLabel1.text = @"UILabel1";
uiLabel1.layer.anchorPoint = CGPointMake(1, 1);

UILabel *uiLabel2 = [[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 20)] autorelease];
uiLabel2.text = @"UILabel2";
uiLabel2.layer.anchorPoint = CGPointMake(1, 1);
uiLabel2.frame = CGRectMake(100, 100, 100, 20);

[self.view addSubview:uiLabel1];
[self.view addSubview:uiLabel2];

enter image description 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-06-10T12:20:59+00:00Added an answer on June 10, 2026 at 12:20 pm

    A CALayer has four properties that determine where it appears in its superlayer:

    • position (which is the same as the view’s center property)
    • bounds (actually only the size part of bounds)
    • anchorPoint
    • transform

    You will notice that frame is not one of those properties. The frame property is actually derived from those properties. When you set the frame property, the layer actually changes its center and bounds.size based on the frame you provide and the layer’s existing anchorPoint.

    You create the first layer (by creating the first UILabel, which is a subclass of UIView, and every UIView has a layer), giving it a frame of 100,100,100,20. The layer has a default anchor point of 0.5,0.5. So it computes its bounds as 0,0,100,20 and its position as 150,110. It looks like this:

    anchor at center

    Then you change its anchor point to 1,1. Since you don’t change the layer’s position or bounds directly, and you don’t change them indirectly by setting its frame, the layer moves so that its new anchor point is at its (unchanged) position in its superlayer:

    anchor at corner

    If you ask for the layer’s (or view’s) frame now, you will get 50,90,100,20.

    When you create the second layer (for the second UILabel), after changing its anchor point, you set its frame. So the layer computes a new position and bounds based on the frame you provide and its existing anchor point:

    anchor at corner with reset frame

    If you ask the layer (or view) for its frame now, you will get the frame you set, 100,100,100,20. But if you ask for its position (or the view’s center), you will get 200,120.

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

Sidebar

Related Questions

I made two different Fibonacci functions, the first one worked perfectly. Then I tried
Context: .Net, C# I want to print a complex number made from two doubles.
I made a toolbar with two buttons on it. I then created two outlets
I made an usercontrol and it works great, but when I put two instances
i have made two view classes in first view class i am making more
I made two classes in which one is main and other one is a
Recently i made two template classes,according to the book Modern C++ design. I think
I've created a simple webapp with user authentication. I've made two models: Users for
Our application is currently made up of two big entities: C# ASPX files, and
I'm putting together a simple test made up of two tutorials available online for

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.