Skip to content

Hairline extends UIView and create crisp half pixel separators (Horizontal & Vertical)

License

Notifications You must be signed in to change notification settings

vinaychopra90/HairLine

Repository files navigation

HairLine

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 :

  1. Creating custom navigation bar separator
  2. Creating UITableViewCell / UICollectionViewCell separators.
  3. 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:

  1. Create a 1px View
  2. Apply necessary constraints
  3. 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.

screen shot 2018-03-09 at 5 26 30 pm

Contributing

Issues and Feature Requests are welcome!

Author

Created with ❤️ by Vinay Chopra

Twitter: @vinaychopra90

Cheers.

About

Hairline extends UIView and create crisp half pixel separators (Horizontal & Vertical)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published