import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIColor.redColor().as1ptImage()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension UIColor {
func as1ptImage() -> UIImage {
UIGraphicsBeginImageContext(CGSizeMake(1, 1))
let ctx = UIGraphicsGetCurrentContext()
self.setFill()
CGContextFillRect(ctx, CGRect(x: 0, y: 0, width: 1, height: 1))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
但是当我添加一个UITableView它不会出现在它,当我加入UISearchView出现,但删除导航栏。
任何人都知道如何解决这个问题?
谢谢,我在哪里把扩展的UIColor ? – TheoF
无论你喜欢。如果你有其他的UIColor扩展名,你可以把它们放在一起,或者你可以为这个扩展名创建一个新文件,或者你可以将扩展名设置为私有的,并将它与UIViewController类一起使用。 –
我在问,因为它显示错误说“声明只在文件范围有效”。 – TheoF