Swift下隱藏navigationBar下面那天橫線

來源:互聯網
上載者:User


說實話Google了一大圈,最後還是在Stack Overflow上找到了自己想要的答案,但是在swift裡面還像沒有imageWithColor方法,只能自訂了

下面是代碼

func shadowImageLine() -> Void {        self.navigationController?.navigationBar .setBackgroundImage(imageWithColor(UIColor.redColor()), forBarMetrics: UIBarMetrics.Default)        self.navigationController?.navigationBar.shadowImage = UIImage()    }    func imageWithColor(color: UIColor) -> UIImage{        let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)        UIGraphicsBeginImageContext(rect.size)        let context = UIGraphicsGetCurrentContext()                CGContextSetFillColorWithColor(context, color.CGColor)        CGContextFillRect(context, rect)                let image = UIGraphicsGetImageFromCurrentImageContext()        UIGraphicsEndImageContext()        return image    }

這是最終的效果




相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.