Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to account for the height of the navigation bar in SnapKit?

I am fairly new to using SnapKit and I've searched everywhere on the internet but could not find the right resource that answers my question. So here it goes. I have one UIView that is a subview of the view of the controller and I want its height to change dynamically with the height of its superview. So like this:

make.top.left.right.equalTo(view)
make.height.equalTo(view.safeAreaLayoutGuide.snp.height).multipliedBy(0.25)

However, when the view controller goes inside a navigation controller and shows a navigation bar, that constraint I set above does not calculate the height of the navigation bar that appears. So the navigation bar just covers my custom view. I am trying to figure out how to account for the height of the navigation bar when you try to set up constraint like above. Any ideas? I've tried make.height.equalTo(view.layoutMarginsGuide.snp.height).multipliedBy(0.25), but no luck.

like image 994
Junsu Kim Avatar asked Dec 07 '25 14:12

Junsu Kim


1 Answers

am assuming you cant cope with navigation bar.

make.top.equalTo(view.safeAreaLayoutGuide)
make.leading.trailing.equalTo(view)
make.height.equalTo(view).multipliedBy(0.25)                       
like image 54
Divine Avatar answered Dec 10 '25 05:12

Divine