[Xcode 實際操做]4、經常使用控件-(15)MKMapView加載簡單視圖

目錄:[Swift]Xcode實際操做html

本文將演示地圖視圖的使用方法。swift

在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】框架

 1 import UIKit
 2 //首先往視圖控制器類文件中,引入地圖框架
 3 import MapKit
 4 
 5 //添加地理地圖代理協議MKMapViewDelegate
 6 class ViewController: UIViewController, MKMapViewDelegate {
 7 
 8     override func viewDidLoad() {
 9         super.viewDidLoad()
10         // Do any additional setup after loading the view, typically from a nib.
11         //初始化一個地圖對象,並指定其位置和尺寸
12         let map = MKMapView(frame: self.view.bounds)
13         //在地圖中,顯示當前用戶的地理位置
14         map.showsUserLocation = true
15         //設置地圖視圖的顯示樣式,爲衛星視圖模式
16         map.mapType = MKMapType.satellite
17         
18         //將地圖視圖對象,添加到當前視圖控制器的根視圖
19         self.view.addSubview(map)
20     }
21 
22     override func didReceiveMemoryWarning() {
23         super.didReceiveMemoryWarning()
24         // Dispose of any resources that can be recreated.
25     }
26 }
相關文章
相關標籤/搜索