Mako Shan

Mako 是一名密码朋克爱好者
这里是我记录生活和成长的地方

联系我的微信号
👏欢迎一起交流学习

Swift Tip

在safari打开网页

if let url = NSURL(string: "http://sspai.com") {
    UIApplication.sharedApplication().openURL(url)
}

NSURLConnection 网路连接

var url = NSURL(string: "http://sspai.com")
var request = NSURLRequest(URL: url)

NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) in
        println(NSString(data: data, encoding: NSUTF8StringEncoding))
})

对话框

let alertView:UIAlertView = UIAlertView()
alertView.title="提示"
alertView.message="恭喜你,你中奖了!"
alertView.addButtonWithTitle("确定")
alertView.show()

或者
var alert:UIAlertController = UIAlertController(title: "提示", message: "恭喜你,你中奖了!", preferredStyle: UIAlertControllerStyle.Alert)
var action: UIAlertAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: {
    ac -> Void in
})
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)

导航栏

//设置导航栏按钮(左边)
let leftBarButtonItem:UIBarButtonItem = UIBarButtonItem(title: "主页", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("showMain"))
self.navigationItem.leftBarButtonItem = leftBarButtonItem

//设置导航栏按钮(右边)
let rightBarButtonItem:UIBarButtonItem = UIBarButtonItem(title: "设置", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("showSetting"))
self.navigationItem.rightBarButtonItem = rightBarButtonItem

//设置导航栏名称
self.navigationItem.title="全国主要城市PM2.5"
0
OC Tip
目录