私は、2枚の画像がある - self.profileImageView、20ピクセル互いに離間されself.profileImageViewOfLoggedInUserを及びIビューにそれらをセンタリングします。以下はセンタリング画像 - 自動レイアウトのObjective C
は私が追加するコードを教えてください私のコード
static CGFloat const MeetingDetailNameLabelMarginX = 20;
NSDictionary *views = @{
@"imageView": self.profileImageView,
@"imageViewForLoggedInUser": self.profileImageViewOfLoggedInUser,
@"nameLabel": self.nameLabel,
@"companyNameLabel": self.companyNameLabel,
@"positionLabel": self.positionLabel,
@"statusLabel": self.statusLabel,
};
NSDictionary *metrics = @{
@"imagePaddingLeft": @(MeetingDetailImageViewMarginX),
@"imagePaddingTop": @(MeetingDetailImageViewMarginY),
@"nameLabelPaddingLeft": @(MeetingDetailNameLabelMarginX),
@"nameLabelPaddingRight": @(MeetingDetailNameLabelMarginRightX),
@"nameLabelPaddingTop": @(MeetingDetailImageViewSize + MeetingDetailImageViewMarginY),
@"imageSize": @(MeetingDetailImageViewSize),
@"nameLabelHeight": @(nameLabelFrame.size.height),
@"otherLabelHeight": @(MeetingDetailOtherLabelHeight),
@"dateLabelWidth": @(self.dateLabel.frame.size.width),
@"statusLabelWidth": @(statusFrame.size.width),
@"statusLabelMarginLeftFromView": @(MeetingDetailImageViewMarginX),
};
// image left and width
[self.detailContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[imageView(imageSize)]"
options:0
metrics:metrics
views:views]];
[self.detailContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-imagePaddingLeft-[imageViewForLoggedInUser(imageSize)]"
options:0
metrics:metrics
views:views]];
// image top and height
[self.detailContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-imagePaddingTop-[imageView(imageSize)]"
options:0
metrics:metrics
views:views]];
[self.detailContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-imagePaddingTop-[imageViewForLoggedInUser(imageSize)]"
options:0
metrics:metrics
views:views]];
です。
は、以下のコードを追加することで、スクリーンショットです: - あなたはそれはスーパーだImageViewの相対を中心にしたい場合は
NSLayoutConstraint *centerXConstraint = [self.detailContainer.centerXAnchor constraintEqualToAnchor:_profileImageView.centerXAnchor];
[self.detailContainer addConstraint:centerXConstraint];
ありがとう@Eugene、私は上記のコードを試して、それは最初の画像を中心にしますが、2番目の画像を中心にしません。だから、私は2つの画像の割合を表示したい。助けてください –