Post

Replies

Boosts

Views

Activity

Reply to mapItem.openInMaps Unknown Location
@Claude31 Sorry, I think I misled you. I did not added the main class to the question. Thats why your code can't work that way. Here is the correct code: class AnnotationButton: UIButton {     var annotation: MKPointAnnotation? } class ViewController: UIViewController, MKMapViewDelegate {     func findPlace(_ places: [Place]) {       for place in places {         let annotations = MKPointAnnotation()         annotations.title = place.name         annotations.subtitle = place.description         annotations.coordinate = CLLocationCoordinate2D(latitude:           place.lattitude, longitude: place.longtitude)         mapView.addAnnotation(annotations)       }     } func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {         guard !(annotation is MKUserLocation) else { return nil }         let identifier = "identifier"         guard let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier, for: annotation) as? MKMarkerAnnotationView else { return nil } let leftButton = AnnotationButton(frame: CGRect(           origin: CGPoint.zero,           size: CGSize(width: 25, height: 25)))         leftButton.setBackgroundImage(#imageLiteral(resourceName: "nav"), for: .normal)         annotationView.leftCalloutAccessoryView = leftButton         leftButton.addTarget(self, action: #selector(didClickDetailDisclosureNavigation(button:)), for: .touchUpInside)         if let pointAnnotation = annotation as? MKPointAnnotation {                     leftButton.annotation = pointAnnotation                 }     @objc func didClickDetailDisclosureNavigation(button: AnnotationButton) {             let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]             if let mapItem = button.annotation?.mapItem {                     mapItem.openInMaps(launchOptions: launchOptions)     }     } extension MKPointAnnotation {     var mapItem: MKMapItem {         let placemark = MKPlacemark(coordinate: self.coordinate)         return MKMapItem(placemark: placemark)     } }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
@Claude31, for now I think Im doing fine with the collectionView. I will put a tick, when I'll finish. How can I input distance from some point in the label? I have locationLabel in this ViewController (In the cell in CollectionView), but I would like to input the distance in kilometers between user current location and from the point in Struct, which is in another ViewController called simply 'ViewController': This is this struct from another ViewController:     struct Place {       let name: String       let description: String       let typ: String       let lattitude: CLLocationDegrees       let longtitude: CLLocationDegrees         var coordinate: CLLocationCoordinate2D {             .init(latitude: lattitude, longitude: longtitude)         }     }     let places = [Place(name: "one", description: "desc_one", typ: "one", lattitude: 81.108187, longtitude: 37.075812),                    Place(name: "two", description: "two", typ: "two", lattitude: 31.076187, longtitude: 87.000563),                    Place(name: "Three", description: "three", typ: "three", lattitude: 31.096688, longtitude: 26.991312),
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
Ok, so far I got this, and the layout is ride off: import UIKit class TrasyOpisyController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return nazwy_modernizm.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ModernizmCollectionViewCell", for: indexPath as IndexPath) as! ModernizmCollectionViewCell cell.imageCell.image=self.images_modernizm[indexPath .row] cell.title.text=self.names_modernizm[indexPath .row] cell.subTitle.text=self.opisy_modernizm[indexPath .row] //cell.locationLabel.text=self.czas_rower[indexPath .row] return cell } @IBOutlet weak var collectionView: UICollectionView! func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){ collectionView.deselectItem(at: indexPath, animated: true) //this does not work } let names_modernizm = [("One"),("Two"),("Three")] let opisy_modernizm = [("one"),("two"),("three")] let images_modernizm = [UIImage(named: "one.jpeg"), UIImage(named: "two.jpeg"), UIImage(named: "three.jpeg")] override func viewDidLoad() { super.viewDidLoad() collectionView.delegate = self collectionView.dataSource = self // collectionView.collectionViewLayout = UICollectionViewFlowLayout() } } //extension ViewController: UICollectionViewDelegateFlowLayout{ // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { // return CGSize(width: 10, height: 10) // } //} // I was trying with this, but it gets worst And ModernizmCollectionViewCell: import UIKit class ModernizmCollectionViewCell: UICollectionViewCell { @IBOutlet weak var imageCell: UIImageView! @IBOutlet weak var iconLabel: UIImageView! @IBOutlet weak var title: UILabel! @IBOutlet weak var subTitle: UILabel! @IBOutlet weak var locationLabel: UILabel! override func awakeFromNib() { super.awakeFromNib() // Initialization code } } In storyboard it looks fine, but when I run the app everything rides off:
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to Problem with layout - CollectionView
Ok, so I have added this in ViewController.swift:  override func viewDidLoad() {         super.viewDidLoad()         collectionView.delegate = self         collectionView.dataSource = self         collectionView.collectionViewLayout = UICollectionViewFlowLayout()             } extension TrasyOpisyController: UICollectionViewDelegateFlowLayout{     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         return CGSize(width: 700, height: 700)     } } And it looks much better: Now I need to realize how to center it to be in the center of VC, like here:
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21