-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJournalEntryDetailViewController.swift
55 lines (49 loc) · 1.95 KB
/
JournalEntryDetailViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// JournalEntryDetailViewController.swift
// JRNL
//
// Created by iOS17Programming on 07/10/2023.
//
import UIKit
import MapKit
class JournalEntryDetailViewController: UITableViewController {
// MARK: - Properties
@IBOutlet var dateLabel: UILabel!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var bodyTextView: UITextView!
@IBOutlet var photoImageView: UIImageView!
@IBOutlet var mapImageView: UIImageView!
@IBOutlet var ratingView: RatingView!
var selectedJournalEntry: JournalEntry?
override func viewDidLoad() {
super.viewDidLoad()
dateLabel.text = selectedJournalEntry?.dateString
ratingView.rating = selectedJournalEntry?.rating ?? 0
titleLabel.text = selectedJournalEntry?.entryTitle
bodyTextView.text = selectedJournalEntry?.entryBody
if let photoData = selectedJournalEntry?.photoData {
photoImageView.image = UIImage(data: photoData)
}
getMapSnapshot()
}
// MARK: - Private methods
private func getMapSnapshot() {
if let lat = selectedJournalEntry?.latitude, let long = selectedJournalEntry?.longitude {
let options = MKMapSnapshotter.Options()
options.region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: lat, longitude: long), span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
options.size = CGSize(width: 300, height: 300)
options.preferredConfiguration = MKStandardMapConfiguration()
let snapShotter = MKMapSnapshotter(options: options)
snapShotter.start {
snapShot, error in
if let snapShot = snapShot {
self.mapImageView.image = snapShot.image
} else if let error = error {
print("snapShot error: \(error.localizedDescription)")
}
}
} else {
self.mapImageView.image = nil
}
}
}