본문 바로가기

iOS/Swift

(39)
[ios - swift] UILabel attributedString line spacing extension NSAttributedString { func withLineSpacing(_ spacing: CGFloat) -> NSAttributedString { let attributedString = NSMutableAttributedString(attributedString: self) let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineBreakMode = .byTruncatingTail paragraphStyle.lineSpacing = spacing attributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0..
[ios - swift] date to string, string to date public static func dateToString(dateFormat: String, date: Date) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = dateFormat return dateFormatter.string(from: date) } public static func stringTodate(dateFormat: String, stringDate: String) -> Date { let dateFormatter = DateFormatter() dateFormatter.dateFormat = dateFormat return dateFormatter.date(from: stringDate) ?? Dat..
[ios - swift] alert let alert = UIAlertController(title: "Warning", message: NSLocalizedString("not valid qr code", comment: ""), preferredStyle: UIAlertController.Style.alert) alert.addAction(UIAlertAction(title: NSLocalizedString("confirm", comment: ""), style: .default){ (action) in //button alick event }) present(alert, animated: true, completion: nil)
[ios - swift] textfield return override func viewDidLoad() { super.viewDidLoad() emailTextField.delegate = self pwTextField.delegate = self } extension LoginView: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { if textField == emailTextField { pwTextField.becomeFirstResponder() } else { pw.resignFirstResponder() } return true } }
[iOS - swift] 특정 문자열 변경 var str = "Hello?" str = str.replacingOccurrences(of: "?", with: "!") print(str) //Hello!
화면 터치시 키보드 내리기 override func touchesBegan(_ touches: Set, with event: UIEvent?) { super.touchesBegan(touches, with: event) self.view.endEditing(true) }
M1 ios Swift CocoaPods 에러 pod init까지는 별 문제가 없이 podfile이 설치되었지만 podfile 안에 추가한 라이브러리들을 사용하기 위해 pod install을 실행하니 에러 메세지가 떴다. 오류를 검색해보니 m1 맥에서 나는 오류라고 한다. pod install을 하기 전에 두가지 코드를 실행하니 문제 없이 라이브러리를 추가해서 쓸수 있었다. $ sudo arch -x86_64 gem install ffi $ arch -x86_64 pod install 두가지 코드를 실행 후 podfile에 라이브러리를 추가해주고 pod install을 실행하면 된다.
how to start UICollectionview with some position not 0 class MainViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { /.../ } override func viewWillLayoutSubviews() { self.collectionView.scrollToItem(at: IndexPath(row: //write position you want to start//, section: 0), at: .centeredHorizontally, animated: false) }..
zoomable image pager with UICollectionView (swift) 안드로이드의 이미지 뷰페이저와 같이 가로 스크롤 및 확대 가능한 이미지 뷰 페이지 만들기 zoomable image pager with horizontal UICollection like Image ViewPager at Android Test Device 1. iPhone Xs (ios 15.1) 2. iPhone8 (ios 13.7) 구현목표 1. 가로 스크롤 되는 페이저 구현 2. 화면에 이미지 하나가 가득차게 표기 3. 이미지 확대 기능 4. 이미지 개수 만큼 indicator 표기 구성요소 Component UIViewController - UICollectionView -- UICollectionViewCell --- ScrollVIew ---- ImageView - UIPageControl ..