Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical-center UIImageView with snapkit

Tags:

swift

snapkit

How can I vertical-center a UIImageView in super view with the snapkit? I tried like this:

 imageview.snp.makeConstraints { (make) in
            make.centerY.equalTo(view.center.y);

        }

but seems not well.How can I use the snapkit

like image 331
Z.Q Avatar asked Jan 03 '23 03:01

Z.Q


2 Answers

Try following code

Imageview.snp.makeConstraints { (make) in
     make.left.equalTo(view.snp.left).offset(50)
     make.centerY.equalTo(self.view)
     make.width.height.equalTo(100)
}
like image 173
Bhavesh.iosDev Avatar answered Jan 19 '23 09:01

Bhavesh.iosDev


It's not enough to give the imageView a centerY only , you need to give it also width,height and x constraint , so try this

imageview.snp.makeConstraints { (make) in
      make.left.equalTo(view.snp.left).offset(50)
      make.centerY.equalTo(self.view)
      make.width.height.equalTo(100)
}
like image 33
Sh_Khan Avatar answered Jan 19 '23 09:01

Sh_Khan