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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:20:17+00:00 2026-06-15T21:20:17+00:00

I am trying to have the auto layout manager adjust the center point of

  • 0

I am trying to have the auto layout manager adjust the center point of a view, based on the width of the super view. I don’t understand why that is an ‘Invalid Pairing’ of the attributes (as told by the crash and NSInvalidArgumentException)

UIView *ac;
NSLayoutConstraint *cXloc = [NSLayoutConstraint constraintWithItem:ac 
                                                         attribute:NSLayoutAttributeCenterX 
                                                         relatedBy:NSLayoutRelationEqual 
                                                            toItem:ac.superview 
                                                         attribute:NSLayoutAttributeWidth 
                                                        multiplier:.1 
                                                          constant:x*ac.superview.frame.size.width*.2];
[ac.superview addConstraint:cXloc];

Could someone explain why this is an ‘Invalid paring’ and how I should approach this?
Thanks

  • 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-15T21:20:18+00:00Added an answer on June 15, 2026 at 9:20 pm

    If you relate ac’s AttributeCenterX to its superview’s AttributeCenterX, AttributeLeading, or AttributeTrailing, you should be able to express your desired constraint using the multiplier and constraint. Keep in mind that the constant is evaluated only when the constraint is created, and your example’s constant wouldn’t update as ac.superview’s width changes.

    If you can express in words how you’d like ac positioned relative to its superview, we can suggest a constraint.

    Edit

    Here’s an example with 5 NSButtons. They themselves and the space between them expand so that the spaces are 30% as wide as the buttons, all the buttons have the same width, and all the spaces have the same width. Creating 4 invisible NSViews just for spacing is pretty cumbersome, especially considering you’ve got it working outside of autolayout. But in case you’re curious:

    // Assuming these NSViews and NSButtons exist,
    //NSView* superview ;
    //NSButton *buttonOne, *buttonTwo, *buttonThree, *buttonFour, *buttonFive ;
    
    
    [superView removeConstraints:superView.constraints] ;
    
    // Create empty NSViews to fill the space between the 5 buttons.
    NSView* spaceOne = [NSView new] ;
    NSView* spaceTwo = [NSView new] ;
    NSView* spaceThree = [NSView new] ;
    NSView* spaceFour = [NSView new] ;
    spaceOne.translatesAutoresizingMaskIntoConstraints = NO ;
    spaceTwo.translatesAutoresizingMaskIntoConstraints = NO ;
    spaceThree.translatesAutoresizingMaskIntoConstraints = NO ;
    spaceFour.translatesAutoresizingMaskIntoConstraints = NO ;
    [superView addSubview:spaceOne] ;
    [superView addSubview:spaceTwo] ;
    [superView addSubview:spaceThree] ;
    [superView addSubview:spaceFour] ;
    
    NSDictionary* views = NSDictionaryOfVariableBindings(superView,buttonOne,buttonTwo,buttonThree,buttonFour,buttonFive,spaceOne,spaceTwo,spaceThree,spaceFour) ;
    
    // Vertically align buttonOne to its superview however you like.
    [superView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[buttonOne]"  options:0  metrics:nil  views:views ] ] ;
    
    // Make the "space" NSViews' widths equal and >= 10. Make the buttons' widths equal.
    [superView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[buttonOne][spaceOne(>=10)][buttonTwo(==buttonOne)][spaceTwo(==spaceOne)][buttonThree(==buttonOne)][spaceThree(==spaceOne)][buttonFour(==buttonOne)][spaceFour(==spaceOne)][buttonFive(==buttonOne)]|"  options: NSLayoutFormatAlignAllCenterY  metrics:nil  views:views ] ] ;
    // Make the "space" NSViews' widths 30% of the NSButtons' widths.
    [superView addConstraint: [NSLayoutConstraint constraintWithItem: spaceOne
                                                           attribute: NSLayoutAttributeWidth
                                                           relatedBy: NSLayoutRelationEqual
                                                              toItem: buttonOne
                                                           attribute: NSLayoutAttributeWidth
                                                          multiplier: 0.3
                                                            constant: 0 ] ] ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a layout where I have a Div that gets added
I'm trying to figure out auto layout constraints with a view in portrait and
I am trying to have a textBox auto complete with values from a database.
I am trying to have a plugin I am developing auto-reload every time I
Im trying to get some auto complete to work. I have this URL i
I am trying to have a table like this: Manager Expert Adminis. Staff Dept
I am trying to have a method that takes in a username and will
I am trying to use the new Auto Layout in Lion because it seems
I am trying to learn and use html5 and have a basic layout but
I am trying to get to the point where I have a Input (EditText)

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.