LoginSignup
0
0

More than 1 year has passed since last update.

UITextViewのtextに表示する文字列を改行して読みやすくする。

Last updated at Posted at 2021-09-07

今回の内容

  • 表示する文字列を改行して、読みやすくします。
  • 今回、私が使った改行方法についてだけを投稿しています。

2A7C86A5-A0F6-47F3-A771-4E1FD3D52464_1_201_a.jpeg

コードと簡単解説

  • 緯度と経度を取得して、住所などに変換した値をUITextViewのtextに表示しています。

  • 表示したい文字列などを,下記のコードのように"""で囲むと上の画像の様に改行します。


           ~~~~~~~~~~省略~~~~~~~~~~

    @IBOutlet weak var currentLocationTextView: UITextView!

           ~~~~~~~~~~省略~~~~~~~~~~

    //使用者の現在地の緯度と経度を取得して、住所か建物の名前などに変換
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: (locations.first?.coordinate.latitude)!, longitude: (locations.first?.coordinate.longitude)!)) { placeMark, error in

            if error != nil{

                return
            }

            if let resultPlaceMark = placeMark?.first{

                if resultPlaceMark.administrativeArea != nil || resultPlaceMark.locality != nil{

                    self.currentLocationTextView.text = """
                        緯度
                        [\((locations.first?.coordinate.latitude)!)]

                        経度
                        [\((locations.first?.coordinate.longitude)!)]

                        場所
                        [\(resultPlaceMark.administrativeArea!)]
                        [\(resultPlaceMark.subLocality!)]
                        [\(resultPlaceMark.name!)]
                        """

                }else{

                    self.currentLocationTextView.text = resultPlaceMark.name!

                }
            }
        }
    }

終わり

間違いの指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0