【发布时间】:2017-10-10 14:50:22
【问题描述】:
我需要使用 UICollectionView 的锚约束来构建 UIView。我插入的锚点都是正确的,但我的 widthAncor 有问题……我解释一下:
这是我的 CollectionView
_monthCollection = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:monthCollectionLayout];
[self addSubview:_monthCollection];
[_monthCollection.topAnchor constraintEqualToAnchor:self.topAnchor constant:65].active = YES;
[_monthCollection.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:2].active = YES;
[_monthCollection.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:0].active = YES;
[_monthCollection.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:0].active = YES;
这是我添加的 UIView
UIView *cursor = [[UIView alloc] init];
cursor.backgroundColor = [UIColor colorWithHexString:@"#E66163" setAlpha:.4];
cursor.layer.borderColor = [UIColor colorWithHexString:@"#E66163" setAlpha:1].CGColor;
cursor.layer.borderWidth = 1;
cursor.layer.cornerRadius = 15;
cursor.translatesAutoresizingMaskIntoConstraints = NO;
[_monthCollection addSubview:cursor];
[cursor.topAnchor constraintEqualToAnchor:_monthCollection.topAnchor constant:0].active = YES;
[cursor.leftAnchor constraintEqualToAnchor:_monthCollection.leftAnchor constant:0].active = YES;
[cursor.widthAnchor constraintEqualToConstant:_monthCollection.frame.size.width].active = YES;
[cursor.bottomAnchor constraintEqualToAnchor:_monthCollection.bottomAnchor constant:0].active = YES;
我需要 UIVIEW 的宽度等于 _monthCollection.frame.size.width / 3
我尝试了所有方法,但似乎约束我什么都不在乎..我无法得到任何结果...
所以我想知道......当我使用锚约束时如何插入我的宽度?
【问题讨论】:
标签: ios objective-c autolayout constraints