IOS development of Xib, Storyboard, code mix automatically layout

Recently in the project, some problems. Especially before the maintenance of the code written by people, probably a lot of XIB layout has been good. However, in subsequent requirements, you want to modify some UILabel or other constraints inside. So here, my revised approach to say, to share with you.

Love / / points every every every every every every every every every every every every every every every

Train of thought: first of all, to get the constraint of the modified control. Pull to file and make changes.

Simple examples are as follows:

One

IOS development of Xib, Storyboard, code mix automatically layout
constraint 1, the following figure will remove the right diagram.

2. find the constraint that you want to modify and drag it into the file

IOS development of Xib, Storyboard, code mix automatically layout
, take care of the constraints you want to modify

3. code as follows

//Created, by, Zhang Jian, on, 2017/6/2.,

//Copyright 2017 All rights reserved. Zhang Jian.

/ /

#import “ViewController.h””

@interfaceViewController () {

NSString*nameStr;

}

@property (weak, nonatomic) IBOutletUILabel*nameLb;

This is a constraint on the Xib / /.

@property (weak, nonatomic) IBOutletNSLayoutConstraint*nameLbWidth;

@end

@implementationViewController

– – (void) viewDidLoad {

[superviewDidLoad];

Delay / loading. When necessary

[selfperformSelector:@selector (changeNameLbWidth) withObject:nilafterDelay:0.1];

}

– – (void) changeNameLbWidth{

Self.nameLb.text=@ “my sword has long been starved.”! “;

NameStr=self.nameLb.text;

CGFloatnameWidth =self.nameLb.frame.size.width;

//float nameWidth = [self, getWidthFromString:nameStr, height:self.nameLb.frame.size.height, font:[UIFont, systemFontOfSize:15]];

Self.nameLbWidth.constant= nameWidth +100;

Self.nameLb.frame=CGRectMake (self.nameLb.frame.origin.x, self.nameLb.frame.origin.y, nameWidth, self.nameLb.frame.size.height);

}

Love / / points every every every every every every every every every every every every every every every every every every every every every every every every every every every every every. Up

@end

Love / / points every every every every every every every every every every every every every every every