Skip to content

Instantly share code, notes, and snippets.

@yuxiangq
Created April 6, 2015 13:02
Show Gist options
  • Save yuxiangq/dc9faab124f1eedf82a8 to your computer and use it in GitHub Desktop.
Save yuxiangq/dc9faab124f1eedf82a8 to your computer and use it in GitHub Desktop.
设置约束
-(void)p_updateConstraints{
[self.contentView removeConstraints:self.contentView.constraints];
NSDictionary *views=@{@"contentLabel":self.contentLabel};
NSMutableArray *constraints=[NSMutableArray array];
//设置水平约束
[constraints addObjectsFromArray:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-5-[contentLabel]-5-|"
options:0
metrics:nil
views:views]];
//设置垂直约束
[constraints addObjectsFromArray:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:|-5-[contentLabel]-5-|"
options:0
metrics:nil
views:views]];
[self.contentView addConstraints:constraints];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment