答案 0 :(得分:0)
地图视图顶部的子视图。我是一个iOS资源。 UIButton - >类型 - >详细信息披露
答案 1 :(得分:0)
在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)
}
然后添加按钮的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()
}
对于另外两个UIViews,只需为温度创建一个UILabel,为云图标创建一个UIImageView。对于UILabel和UIImageView的背景颜色及其角半径,您可以执行类似于我为按钮所做的操作,但这次选择UIImageView的右角和UILabel的左角。
以下是输出:当然,您可以为按钮使用尺寸更大的图标图像。