voglio centrare UIImageView (self.showImageView
) in vista del contenitore (self.view
)Come fare un UIImageView, centro in verticale in un contenitore con i vincoli di programmazione
ho provato sotto il codice è did't lavoro:
NSLayoutConstraint *xCenterConstraint = [NSLayoutConstraint constraintWithItem:self.showImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
[self.view addConstraint:xCenterConstraint];
NSLayoutConstraint *yCenterConstraint = [NSLayoutConstraint constraintWithItem:self.showImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
[self.view addConstraint:yCenterConstraint];
trascinare il layout per visualizzare e aggiungere "allinea verticalmente al centro del container" – Sam
Per me, il modo semplice per rendere questo non è l'utilizzo del layout automatico, solo rendere questo: self.showImageView.center = self.view.center; –