반응형

iOS 197

[iOS, Swift] 체크박스 구현하기

iOS 16.1, Xcode 14.2, Swift 5, UIKit 환경에서 진행했습니다. iOS에서는 체크박스와 라디오버튼이 기본적으로 제공되어지지 않습니다. 그러나 체크박스는 기본적인 버튼 속성을 사용하여 구현할 수 있습니다. 버튼을 생성할 때에, setImage 설정할 때에 state 값이 normal인 것과 selected인 값을 따로 설정해줍니다. lazy var checkButton: UIButton = { var button: UIButton = UIButton(type: .custom) button.translatesAutoresizingMaskIntoConstraints = false button.setImage(UIImage(systemName: "rectangle"), for: .nor..

iOS/코드조각 2023.02.24

[iOS, Swift] SF Symbol 활용하기

iOS 16.1, Xcode 14.2, Swift 5, UIKit 환경에서 진행했습니다. SF Symbol은 애플 플랫폼에 기본적으로 저장되어 있는 폰트 또는 이미지 입니다. 기본적인 아이콘을 활용하여 앱을 개발할 때에 SF Symbols 앱이 도움이 됩니다. 만약 Xcode 내에서 ImageView에 애플이 기본적으로 제공하는 이미지를 사용할 경우에는 아래와 같이 사용하면 됩니다. imageView.image = UIImage(systemName: "x.circle.fill") 참조 https://developer.apple.com/sf-symbols/ SF Symbols - Apple Developer With nearly 4,500 symbols, SF Symbols is a library of i..

iOS/팁 2023.02.23

[iOS, Swift] Keyboard로 인해 가려진 뷰 올리기

iOS 16.1, Xcode 14.2, Swift 5, UIKit 환경에서 진행했습니다. 먼저 ViewDidLoad 함수에 키보드가 올라가거나 내려가는 Notification을 구독합니다. func setKeyboardObserver() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboard..

iOS/코드조각 2023.02.22

[iOS, Swift] DocumentPicker 사용예제

iOS 16.1, Xcode 14.2, Swift 5, UIKit 환경에서 진행했습니다. DocumentPickerController에서 forOpeningContentTypes의 타입을 설정하고 초기화를 한 후 present로 pickerController를 띄어준다.설정된 타입은 png로 하였는데, png 파일만 선택이 가능하게끔 됩니다. import MobileCoreServices import UniformTypeIdentifiers @IBAction func didTapDocument(_ sender: UIButton) { let types = UTType(tag: "png", tagClass: UTTagClass.filenameExtension, conformingTo: nil) let doc..

iOS/코드조각 2023.02.20

[iOS, Swift] Left side of mutating operator isn't mutable: 'self' is imutable 오류해결

iOS 16.1, Xcode 14.2, Swift 5, UIKit 환경에서 진행했습니다. Struct 안에 있는 변수를 수정하려고 할 때 'Left side of mutating operator isn't mutable: 'self' is immutable' 과 같은 오류가 발생합니다. 해결방법으로는 함수 func 앞에다가 mutating 이라는 키워드를 붙이면 됩니다. struct LevelStruct { var level: Int = 0 { didSet { print("Level \(level)") } } mutating func levelUp() { level += 1 } } 참조 http://www.yes24.com/Product/Goods/78907450 https://stackoverflow...

iOS/오류해결 2023.02.18

[iOS, Swift] MapKit 사용하여 현재 위치 나타내기

iOS 16.1, Xcode 14.1, Swift 5, UIKit 환경에서 진행했습니다. 스토리보드에서 MapKit을 화면이 꽉차도록 설정합니다. Info.plist 파일에 위와 같이 3가지 설정을 해줍니다. import UIKit import CoreLocation import MapKit class ViewController: UIViewController { @IBOutlet weak var mapView: MKMapView! var locationManager: CLLocationManager = CLLocationManager() var currentLocation: CLLocation! override func viewDidLoad() { super.viewDidLoad() // Do any ..

iOS/코드조각 2023.02.16

[iOS, Xcode] 핸드폰에서 GPS 설정하기(gpx 파일)

iOS 16.1, Xcode 14.1, Swift 5, UIKit 환경에서 진행했습니다. 프로젝트에 GPX 파일을 추가합니다. GPX 파일의 형식은 위와 같이 되어있고, wpt태그 안에 있는 lat, lon 속성에서 값을 설정할 수 있습니다. XCode 아래에 있는 화살표 버튼을 클릭하여 위치 변경을 할 수 있습니다. 핸드폰에서 MapKit을 활용해 실행하면 위와 같이 좌표가 설정되어있는 것을 확인할 수 있습니다.

iOS/팁 2023.02.15
반응형