전체 글 117

swift userdefaults 데이터 저장하기

앱을 구동 시키면 유저가 저장한 정보가 그대로 불러와져야 한다 ~  그럴때 몇가지 방법이 있는데 userdefaults로 데이터 저장을 해보았다.   private func saveProfileInfo(image: UIImage?, name: String, goal: String, memo: String) { if let image = image, let imageData = image.pngData() { UserDefaults.standard.set(imageData, forKey: "profileImage") } UserDefaults.standard.set(name, forKey: "profileName") UserDefa..

카테고리 없음 2024.09.13

swift 프로토콜로 데이터 업데이트 하기 ~

일단 프로필 정보를 만들면 업데이트 해줘야하는데 그걸 한번 구현해봤다.  protocol EditProfileDelegate: AnyObject { func didUpdateProfile(image: UIImage?, name: String, goal: String, memo: String)} 먼저 수정하는 뷰컨에 델리게이트를 선언해준다.  weak var delegate: EditProfileDelegate? @objc func doneButtonTapped(_ sender: UIButton) { // Assuming these outlets exist and are correctly connected let updatedProfileImage = editProfil..

카테고리 없음 2024.09.11

swift 제스처 기능 넣어보기

하다보면 버튼이 꼭 아니더라도 체스처를 통해 버튼처럼 기능을 넣어야 하는 상황이 생길수도 ~ 그래서 만들어봤다.   let tapGestureForImage = UITapGestureRecognizer(target: self, action: #selector(showImageOptions)) editProfileView.profileImageView.isUserInteractionEnabled = true editProfileView.profileImageView.addGestureRecognizer(tapGestureForImage) editProfileView.profileImageButton.addTarget(self, action: #selecto..

카테고리 없음 2024.09.11

swfit 키패드 위쪽에 자동 텍스트 완성 기능 제거하기~

저번에는 철자랑. 대문자, 자동완성 제거였는데 이번에는 추가해서 키패드에 안만 적어도 안녕하세요 나오는 자동완성 제거해보자.  // UITextView의 자동 완성 및 자동 제안 비활성화 editProfileView.memoTextView.autocorrectionType = .no editProfileView.memoTextView.spellCheckingType = .no if #available(iOS 11.0, *) { editProfileView.memoTextView.smartInsertDeleteType = .no }기존에 위에 두개는 자동교정기능과 철자 검사 기능이다 마지막 ios 11 부터 지원되는 기능이니..

카테고리 없음 2024.09.11

swfit 키패드 자동완성 자동수정 비활성화 하기

이건... 사용자에 따라 다르지만 아무튼 비활성화 하고싶을때가 많아서 남깁니다.   // 자동 완성 및 자동 수정 비활성화 설정 editProfileView.nameTextField.autocorrectionType = .no // 자동수정기능 editProfileView.nameTextField.autocapitalizationType = .none // 자동 대문자 editProfileView.nameTextField.spellCheckingType = .no // 자동 철자검사 이 셋중에 필요없는 기능을 no 또는 none 둬서 비활성화 시키시면됩니다.

카테고리 없음 2024.09.11

swfit 키패드 done cancel 버튼 만들기 ~

자주 쓰이는? 자주 쓰는 기능이니 남겨본다.   // 메모 텍스트뷰에 툴바 설정 private func configureMemoTextViewToolbar() { let toolbar = UIToolbar() toolbar.sizeToFit() // 취소 버튼 let cancelButton = UIBarButtonItem(title: "취소", style: .plain, target: self, action: #selector(cancelMemoEditing)) // 완료 버튼 let doneButton = UIBarButtonItem(title: "완료", style: .plain, target: sel..

카테고리 없음 2024.09.11

swift 텍스트 필드 넘버 패드에 캔슬 던 버튼 넣기

가끔 텍스트 필드를 사용하면 필요한게 생긴다. 특히 던 버튼이나 캔슬 버튼이 넘버패드에는 없다... 암튼 왜일까 그래서 커스텀을 해줘야한다.  // Next와 Done 버튼을 각 텍스트 필드에 추가private func addToolbarOnTextFields() { // 첫 번째 텍스트 필드용 툴바 생성 (Cancel + Next 버튼) let toolbarForInput = UIToolbar() toolbarForInput.sizeToFit() let cancelButtonForInput = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelButtonAction)) le..

카테고리 없음 2024.09.08

swift 컬렉션 뷰 셀 텍스트 길이에 따라 유동적으로 크기 정하기

오늘 셀에 텍스트에 따라서 유동적으로 움직이는걸 만들었는데 암튼 자주 쓸거같아 남깁니다  // UICollectionViewDelegateFlowLayout 구현 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let item = rmItems[indexPath.item] // 텍스트 길이에 따라 셀의 폭을 조정 let textWidth = item.weight.width(withConstrainedHeight: ..

카테고리 없음 2024.09.08