Literals in Swift Code
可以讓我們?cè)诖a中快速的選取color,image,file
@1 code
Image Literal
@2 code
Color Literal
@3
file 沒(méi)有UI界面來(lái)選擇文件
不過(guò)也可使用代碼快捷選取
let citiesJSONURL = #fileLiteral(resourceName: "Cities.json")
Navigation bar
1.1 Navigation Prompt
iOS8之前
navigationItem.prompt = "Navigation prompts appear at the top."
必須放在
viewDidAppear
之后鄙麦。這是個(gè)已知Bug
iOS8+
已更正
1.2 Extended navigation bar
navigation bar 在7以后本身的frame 是無(wú)法隨意更改的。不過(guò)有解決辦法
@1 首先將bar 特殊屬性更改掉
//去掉半透明屬性
navigationController!.navigationBar.isTranslucent = false
//去掉bar下面灰色細(xì)線
navigationController!.navigationBar.shadowImage = #imageLiteral(resourceName: "TransparentPixel")
//設(shè)置背景色
navigationController!.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "Pixel"), for: .default)
@2 之后添加我們想要的view在下面,不過(guò)我們得在擴(kuò)展的view下面模擬bar的灰色細(xì)線
利用 陰影
layer.shadowOffset = CGSize(width: 0, height: CGFloat(1) / UIScreen.main.scale)
layer.shadowRadius = 0
layer.shadowColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1).cgColor
layer.shadowOpacity = 0.25
1.3 其他
shadowImage 要與 backgroundImage一同調(diào)用
局部更改back backIndicatorImage和backIndicatorTransitionMaskImage一同調(diào)用
UIImage
1.圖片的拉伸
open func resizableImage(withCapInsets capInsets: UIEdgeInsets) -> UIImage
capInsets 是規(guī)定了不能拉伸的范圍
2.color -> image
UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), false, UIScreen.main.scale)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(UIColor(red: 1, green: 2, blue: 1, alpha: 0).cgColor)
UIRectFill(CGRect(x: 0, y: 0, width: 1, height: 1))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()