LoginSignup
0
0

More than 5 years have passed since last update.

UINavigationBar に下線を入れる

Last updated at Posted at 2018-07-21

最初に1x1pxの画像を生成するメソッドを作成

色を指定して幅1px高さ1pxの画像を生成

extension UIColor {
    func make1ptImage() -> UIImage {
        UIGraphicsBeginImageContext(CGSize(width:1, height:1))
        let ctx = UIGraphicsGetCurrentContext()
        self.setFill()
        ctx!.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
}

作った画像でshadowImageを埋める

self.navigationController?.navigationBar.shadowImage = 
    UIColor.black.make1ptImage()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0