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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:52:16+00:00 2026-06-12T05:52:16+00:00

I have an app whose views are generated programmatically. Example: -(void)loadView { [super loadView];

  • 0

I have an app whose views are generated programmatically. Example:

-(void)loadView
{
    [super loadView];

// SET TOP LEFT BTN FOR NEXT VIEW
UIBarButtonItem *topLeftBtn = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = topLeftBtn;
[topLeftBtn release];

// programmatically set up the view for cart tableView
CGRect iouTableViewFrame = CGRectMake(0, 0, 320, 348);
iouTableView = [[UITableView alloc]initWithFrame:iouTableViewFrame style:UITableViewStylePlain];
[[self iouTableView] setDelegate:self];
[[self iouTableView] setDataSource:self];
[[self view] addSubview:iouTableView];

// set up the summary label
CGRect summaryTableFrame = CGRectMake(0, 348, 320, 18);
UILabel *summaryTableLabel = [[UILabel alloc] initWithFrame:summaryTableFrame];
[summaryTableLabel setFont:[UIFont fontWithName:@"Helvetica" size:14]];
[summaryTableLabel setText:@"   Summary"];
UIColor *labelColor = UIColorFromRGB(MiddleBlueColor);
[summaryTableLabel setBackgroundColor:labelColor];
[summaryTableLabel setTextColor:[UIColor whiteColor]];
[[self view] addSubview:summaryTableLabel];

// set up the summary table
CGRect summaryTableViewFrame = CGRectMake(0, 366, 320, 44);
summaryTableView = [[UITableView alloc]initWithFrame:summaryTableViewFrame style:UITableViewStylePlain];
[summaryTableView setScrollEnabled:NO];
[[self summaryTableView] setDelegate:self];
[[self summaryTableView] setDataSource:self];
[[self view] addSubview:summaryTableView];
}

Yes. I will update to NIBs and use interface builder and storyboard in the future but I have not done ios programming in a year.

With the new iPhone 5 having a different screen size, the app just does not look good and I need to implement auto layout of some sort. Is there a way to do it programmatically for now instead of using IB?

Thanks much!

  • 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-12T05:52:17+00:00Added an answer on June 12, 2026 at 5:52 am

    Yes there is, by using two methods in NSLayoutConstraint

    -(NSArray*)constraintsWithVisualFormat:options:metrics:views:
    -(NSLayoutConstraint*)constraintWithItem:attribute:relatedBy:toItem:attribute:
        multiplier:constant:
    

    The visual format language is all packaged up into an NSString
    So I’ll take your iouTableView for example.

    [self.view addConstraints:[NSLayoutConstraint 
        constraintsWithVisualFormat:@"|[iouTableView]|" 
        options:0 
        metrics:nil 
        views:NSDictionaryOfVariableBindings(iouTableView)]];
    

    The pipe symbol “|” represents the superview’s edge.
    The [] represent a view.
    So what we did there was we hooked the iouTableView’s left and right edge to the left and right edge of its superview.

    Another example of the visual format:
    Let’s hook your table view, summary label and summary table vertically.

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:
        @"V:|[iouTableView(348)][summaryTableLabel(18)][summaryTableView(44)]"
        options:NSLayoutFormatAlignAllLeft
        metrics:nil
        views:NSDictionaryOfVariableBindings(iouTableView, summaryTableLabel, summaryTableView)]];
    

    Now this links up all three views vertically on each of their edges, NSLayoutFormatAlignAllLeft tells all the views to align left and they’ll do so based on other constraints, in this case, the previous constraint.
    The ()s are used to specify the size of the views.

    There’s a bit more like inequalities and priorities as well as the “-” spacer symbol but check out the apple docs for that

    Edit: Corrected the examples to use constraintsWithVisualFormat as shown in the method signature.

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

Sidebar

Related Questions

I have an image in a C# WPF app whose build action is set
I have an app whose navigation tree is described on the attached image. Basically,
I have a simple (Servlet, JSP, and JSTL) web app whose main functionality is
I have a rather simple iPhone app consisting of numerous views containing a single,
Context: I have a clojure-based crossword app whose main ui is a JTabbedPane with
I have an ASP.NET MVC web app whose controllers use WCF to call into
I have an app delegate, whose default view should be preceeded by a modal
I have an app which goes through a set of screens within a navigation
I've got a django app whose views currently use the @login_required decorator. What's the
I have a tab bar app that works. Each tab is a UINavigationController whose

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.