The Beginning iOS 8 Programming with Swift 读书笔记

The Beginning iOS 8 Programming with Swift电子书是全英文的,愣是好多地方没看懂,就找来别人的这些笔记瞅瞅,加深一下理解!

1. 设置图片圆角

thumbnailImageView.layer.cornerRadius = thumbnailImageView.frame.size.width / 2
thumbnailImageView.clipsToBounds = true

2. UIAlertController

// Create an option menu as an action sheet
let optionMenu = UIAlertController(title: nil, message: "What do you want to do?",preferredStyle: .ActionSheet)
// Add actions to the menu
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
optionMenu.addAction(cancelAction)
// Display the menu
self.presentViewController(optionMenu, animated: true, completion: nil)

声明并创建闭包,填充UIAlertAction的handler

let callActionHandler = { 
    (action:UIAlertAction!) -> Void in
    let alertMessage = UIAlertController(title: "Service Unavailable", message: "Sorry,the call feature is not available yet. Please retry later.", preferredStyle: .Alert)
    alertMessage.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
    self.presentViewController(alertMessage, animated: true, completion: nil)
}
let callAction = UIAlertAction(title: "Call " + "123-000-\(indexPath.row)", style: UIAlertActionStyle.Default, handler: callActionHandler)
optionMenu.addAction(callAction)

直接使用闭包,填充UIAlertAction的handler

let isVisitedAction = UIAlertAction(title: "I've been here", style: .Default, handler: {
    (action:UIAlertAction!) -> Void in
    let cell = tableView.cellForRowAtIndexPath(indexPath)
    cell?.accessoryType = .Checkmark
})
optionMenu.addAction(isVisitedAction)

3. 批量初始化一个数组

var restaurantIsVisited = [Bool](count: 21, repeatedValue: false)

4. 隐藏状态栏

override func prefersStatusBarHidden() -> Bool {
    return true
}

info.plist文件中,View controller-based status bar appearance项设为YES,则View controllerstatus bar的设置优先级高于application的设置。为NO则以application的设置为准,view controllerprefersStatusBarHidden方法无效,是根本不会被调用的。

未完,待续。。。

友荐云推荐