Hairline
draws crisp separators in Tableview / Collection View
or NavigationBar
.
Often custom design requires separators which can't be achieved with native separators as its a shadow.
Hairline is used for :
- Creating custom navigation bar separator
- Creating UITableViewCell / UICollectionViewCell separators.
- Separating 2 segments
-----------you can add these separators to achieve hairline behavior
Problems with current Apple API :
Apple does not allow to draw half pixel, even if you forcefully try to give a Constraint constant = 0.5
In case of navigation bar, Apple itself draw a shadow which looks like a hairline of half pixel.
As shadows are drawn outside the view boundary we need to make sure clipsToBounds
& masksToBounds
is false
.
So what Next....trying more alternatives Naah !!!
Here comes rescue from all these tiring stuff :
Pathway:
- Create a 1px View
- Apply necessary constraints
- Provide a class in Identity Inspector
Yeahhh.....Yes you are done with these tiny steps :)
You need to have a checkpoint Sometimes iOS simulator works in a buggy fashion. --------How to Check ,It's simple either increase or decrease the size of simulator (xCode 9+).
Though it works well (100%) on Device.
I have zoomed in the screenshot to show the difference.
Issues and Feature Requests are welcome!
Created with ❤️ by Vinay Chopra
Twitter: @vinaychopra90
Cheers.