How to Draw a single point line in iOS

前端 未结 5 688
北恋
北恋 2020-12-01 19:00

I was wondering what is the best way to draw a single point line? My goal is to draw this line in a tableViewCell to make it look just like the native cell separator. I don\

5条回答
  •  一生所求
    2020-12-01 19:32

    AutoLayout method:

    I use a plain old UIView and set its height constraint to 1 in Interface Builder. Attached it to the bottom via constraints. Interface builder doesn't allow you to set the height constraint to 0.5, but you can do it in code.

    Make a connector for the height constraint, then call this:

    // Note: This will be 0.5 on retina screens
    self.dividerViewHeightConstraint.constant =  1.0/[UIScreen mainScreen].scale 
    

    Worked for me.

    FWIW I don't think we need to support non-retina screens anymore. However, I am still using the main screen scale to future proof the app.

提交回复
热议问题