Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This repository was archived by the owner on May 28, 2025. It is now read-only.

Auto-Layout Constraints showing unexpected behavior #359

Open
@cre8ivepark

Description

@cre8ivepark

I am experiencing unexpected behavior of Auto-Layout Constraints on several places. All of them are added programmatically. Works well on Xcode but shows weird behavior on VS.
Adding some screen shots of Xcode and VS. Please take a look at the spacings marked with red block.

Example of Auto-Layout Constraints for UITableView & UIScrollView:

[tvList setTranslatesAutoresizingMaskIntoConstraints : NO];
[self.view addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : @"H:|-0-[tvList(250)]" options : NSLayoutFormatDirectionLeadingToTrailing metrics : nil views : NSDictionaryOfVariableBindings(tvList)]];
[self.view addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : @"V:|-0-[tvList]-0-|" options : NSLayoutFormatDirectionLeadingToTrailing metrics : nil views : NSDictionaryOfVariableBindings(tvList)]];

[svContent setTranslatesAutoresizingMaskIntoConstraints : NO];
[self.view addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : @"H:[tvList(250)]-0-[svContent]-0-|" options : NSLayoutFormatDirectionLeadingToTrailing metrics : nil views : NSDictionaryOfVariableBindings(tvList, svContent)]];
[self.view addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : @"V:|-0-[svContent]-0-|" options : NSLayoutFormatDirectionLeadingToTrailing metrics : nil views : NSDictionaryOfVariableBindings(svContent)]];

typographyinsight_iw_autolayout1a

Below example uses Auto-Layout Constraints inside the UICollectionViewCell, for the UILabel element:

    label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,150,250)];
    label.textAlignment = UITextAlignmentCenter;
    [self.contentView addSubview:label];
    label.font = [UIFont systemFontOfSize:120];
    label.clipsToBounds = NO;
    label.adjustsFontSizeToFitWidth = YES;
    self.contentView.clipsToBounds = NO;

    [self.contentView setBackgroundColor:[UIColor lightGrayColor]];
    [label setBackgroundColor:[UIColor yellowColor]];
    [label setTranslatesAutoresizingMaskIntoConstraints : NO];
    [self.contentView addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : @"H:|-[label]-|" options : NO metrics : nil views : NSDictionaryOfVariableBindings(label)]];
    [self.contentView addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : @"V:|-[label]-|" options : NO metrics : nil views : NSDictionaryOfVariableBindings(label)]];

typographyinsight_iw_autolayout2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions