전체 글65 이미지를 circle로 만들어주는 clipToBounds if let image: UIImage = ImageManager.shared.getImage(named: "myProfile.jpeg") { self.profileImage.image = image self.profileImage.clipsToBounds = true self.profileImage.layer.cornerRadius = self.profileImage.frame.height/2 self.profileImage.layer.borderWidth = 1 self.profileImage.layer.borderColor = UIColor.black.cgColor } 프로필이미지를 저장까지는 했는데, 애써 예쁘게 만들어놓은 동그라미 모양이 아니라 이미지 그 자체... 사각형으로 나온다면 안되겠습니.. 2022. 12. 22. Initializer for conditional binding must have Optional type, not 'String' 상단의 코드에서 if let docuPath = directory.path로 잡아주게 되면 제목과 같이 조건부 바인딩의 초기자(initializer)는 옵셔널형이어야하며, String일수 없다는 에러가 뜹니다. 있을지 없을지도 모르는데 어떻게 저렇게 쓰니? 하는 것이죠... let docuPath = directory.path if !docupath.isEmpty { let fileNames = try FileManager.default.contentsOfDirectory(atPath: docuPath) for fileName in fileNames { if fileName == named { let filePathName = "\(docuPath)/ \(fileName)" try FileManager... 2022. 12. 22. [권한]아이폰 앨범 접근 권한 확인하기 func albumAccess() -> Bool{ let status = PHPhotoLibrary.authorizationStatus() PHPhotoLibrary.requestAuthorization{status in switch status { case .authorized, .limited : print("album access allowed") case .denied, .restricted : print("album access not allowed") case .notDetermined : print("album access not determined") @unknown default: print("albmum access default") } } if status == PHAuthorizat.. 2022. 12. 21. [사진]UIImagePickerController로 아이폰 기기 앨범의 이미지 선택하기 let imagePickerController = UIImagePickerController() func changeProfileImage() { let ac = UIAlertController(title: "PROFILE_CHANGE_TITLE".localized(), message: "PROFILE_CHANGE_INST".localized(), preferredStyle: .actionSheet) ac.addAction(UIAlertAction(title:"PROFILE_CHANGE_PHOTO".localized(), style: .default, handler: { action in print("camera clicked") })) ac.addAction(UIAlertAction(title:"PRO.. 2022. 12. 21. [사진]Mantis Library 활용하여 이미지 크롭해보기 extension MyPageViewController : CropViewControllerDelegate { func cropViewControllerDidCrop(_ cropViewController: CropViewController, cropped: UIImage, transformation: Transformation) { print("successfully cropped") print("cropped is \(cropped)") self.croppedProfileImage = cropped cropViewController.dismiss(animated: true, completion: nil) } func cropViewControllerDidCancel(_ cropViewController.. 2022. 12. 21. UIImage nil 확인하기(optional, non-optional) var image = UIImage() if image != nil { print("this image is not nil") } Comparing non-optional value of type 'UIImage' to 'nil' always returns false image를 옵셔널로 정의하지 않은 상태에서 nil인지 아닌지를 물어보는 것은 의미가 없습니다. 해당 이미지를 nil인지 아닌지를 확인하기 위해서는 선언할 때에 아래와 같이 옵셔널로 남겨둔 다음 처리가 가능합니다. var image: UIImage? = UIImage() if image != nil { print("this image is not nil") } 만약 불가피한 경우라면 아래와 같이 우회하는 방법을 써서 확인이 가능합니다. va.. 2022. 12. 21. 이전 1 2 3 4 5 6 ··· 11 다음