2017-05-26 54 views
0

我該如何將這些東西添加到我的項目中。它們是否集成在MKMapView如何在swift中添加位置圖標?

我沒有找到關於他們的互聯網什麼。

Screenshot

+1

再見地圖 – Ved

+0

好創建的UIView,但我怎麼能安裝該系統的部位圖標使用外部圖像白化? (對不起,我的英語) –

+0

有沒有像屏幕右上角的「我」圈 –

回答

0
  1. 上創建MKMapView的頂部的兩個按鈕添加則它們的約束在viewDidLayourSubviews功能編寫此代碼舍入所希望的角部和陰影和圖像添加到按鈕。從身份檢查員中選擇他們的淺灰色背景顏色。

    override func viewDidLayoutSubviews() { 
    
    let infoButtonShape = CAShapeLayer() 
    infoButtonShape.bounds = infoButton.frame 
    infoButtonShape.position = infoButton.center 
    
    let locationButtonShape = CAShapeLayer() 
    locationButtonShape.bounds = locationButton.frame 
    locationButtonShape.position = locationButton.center 
    
    
    infoButton.clipsToBounds = true 
    infoButton.layer.masksToBounds = false 
    infoButton.layer.shadowColor = UIColor.white.cgColor 
    infoButton.layer.shadowRadius = 2 
    infoButton.layer.shadowOpacity = 0.5 
    infoButton.layer.shadowOffset = CGSize(width: 2, height: -2) 
    infoButton.layer.shadowPath = UIBezierPath(rect: infoButton.bounds).cgPath 
    
    
    
    locationButton.clipsToBounds = true 
    locationButton.layer.masksToBounds = false 
    locationButton.layer.shadowColor = UIColor.white.cgColor 
    locationButton.layer.shadowRadius = 2 
    locationButton.layer.shadowOpacity = 0.5 
    locationButton.layer.shadowOffset = CGSize(width: -2, height: 2) 
    locationButton.layer.shadowPath = UIBezierPath(rect: locationButton.bounds).cgPath 
    
    infoButton.layer.shouldRasterize = true 
    locationButton.layer.shouldRasterize = true 
    
    locationButtonShape.path = UIBezierPath(roundedRect: locationButton.bounds, byRoundingCorners: [UIRectCorner.bottomLeft , UIRectCorner.bottomRight], cornerRadii: CGSize(width:10.0, height:10.0)).cgPath 
    
    infoButtonShape.path = UIBezierPath(roundedRect: infoButton.bounds, byRoundingCorners: [UIRectCorner.topRight , UIRectCorner.topLeft], cornerRadii: CGSize(width:10.0, height:10.0)).cgPath 
    
    infoButton.layer.mask = infoButtonShape 
    locationButton.layer.mask = locationButtonShape 
    
    infoButton.contentMode = .scaleAspectFit 
    locationButton.contentMode = .scaleAspectFit 
    
    
    infoButton.setImage(#imageLiteral(resourceName: "information-icon-3"), for: .normal) 
    locationButton.setImage(#imageLiteral(resourceName: "LocationArrow-512"), for: .normal) 
    
    
    } 
    
  2. 然後添加按鈕的IBAction更新位置

    let manager = CLLocationManager() 
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    
    //Use location.last add to map then stop updating location 
    manager.stopUpdatingLocation() 
    
    } 
    
    @IBAction func updateLocationAction(_ sender: UIButton) { 
    
    manager.startUpdatingLocation() 
    } 
    
  3. 對於兩個其它UIViews只是創建一個UILabel用於溫度以及用於雲圖標一個的UIImageView。對於UILabel和UIImageView的背景顏色及其圓角半徑,您可以做類似於我爲按鈕所做的操作,但是這次爲UIImageView和UILabel的左角選擇了正確的角點。

這裏是輸出:當然,您可以使用更好的大小的圖標圖像爲您的按鈕。

enter image description here

+0

很棒,謝謝。明天我會試試它! –

0

子視圖在地圖視圖的頂部。我是一個iOS資源。的UIButton - >型 - >詳細披露

相關問題