ios – 如何制作一个uiImageview,以容器方式垂直居中以编程方式约束

ios – 如何制作一个uiImageview,以容器方式垂直居中以编程方式约束,第1张

概述我想在容器视图(self.view)中使UI Imageview(self.showImageView)中心 我尝试下面的代码它没有工作. NSLayoutConstraint *xCenterConstraint = [NSLayoutConstraint constraintWithItem:self.showImgView attribute:NSLayoutAttributeCenterX 我想在容器视图(self.vIEw)中使UI ImagevIEw(self.showImageVIEw)中心

我尝试下面的代码它没有工作.

NSLayoutConstraint *xCenterConstraint = [NSLayoutConstraint constraintWithItem:self.showimgVIEw attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.vIEw attribute:NSLayoutAttributeCenterX multiplIEr:1.0 constant:0];

[self.vIEw addConstraint:xCenterConstraint];NSLayoutConstraint *yCenterConstraint = [NSLayoutConstraint constraintWithItem:self.showimgVIEw attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.vIEw attribute:NSLayoutAttributeCenterY multiplIEr:1.0 constant:0];[self.vIEw addConstraint:yCenterConstraint];
解决方法 尝试这个:
- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    UIVIEw *redVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,200,100)];    redVIEw.backgroundcolor = [UIcolor redcolor];    redVIEw.translatesautoresizingMaskIntoConstraints = NO;    [self.vIEw addSubvIEw:redVIEw];    [redVIEw addConstraint:[NSLayoutConstraint constraintWithItem:redVIEw attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplIEr:1 constant:100]];    [redVIEw addConstraint:[NSLayoutConstraint constraintWithItem:redVIEw attribute:NSLayoutAttributeWIDth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplIEr:1 constant:200]];    [self.vIEw addConstraint:[NSLayoutConstraint constraintWithItem:redVIEw attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.vIEw attribute:NSLayoutAttributeCenterY multiplIEr:1 constant:0]];    [self.vIEw addConstraint:[NSLayoutConstraint constraintWithItem:redVIEw attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.vIEw attribute:NSLayoutAttributeCenterX multiplIEr:1 constant:0]];    [self.vIEw addSubvIEw:redVIEw];}
总结

以上是内存溢出为你收集整理的ios – 如何制作一个uiImageview,以容器方式垂直居中以编程方式约束全部内容,希望文章能够帮你解决ios – 如何制作一个uiImageview,以容器方式垂直居中以编程方式约束所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1111306.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存