0

Good morning I am writing an app in Swift 3.1, and one of the features that I would like to provide is that the user can choose their own background for the main View and keep it as part of the application.

I know how to do it at design time, but what I want is to allow the user once they install the application on their devices to select a picture from the photo library and use that as background of the main View. Also I would like to make sure the app doesn't the depend on the photo library after the image was set as background, in other words, I want to copy the image to the app so if the user deletes the image from the photo library, I have a copy of the image as part of the app.

May I ask if what I want to achieve is possible? If so may I ask for some code guidance please?

Thanks in advance.

JuValencia
  • 212
  • 1
  • 3
  • 17

1 Answers1

0

Yes this can be acheive by following steps:

1) You need to implement UIImagePickerController to select a photo from photos library.

https://turbofuture.com/cell-phones/Access-Photo-Camera-and-Library-in-Swift

2) You need to write a code to save that image in your Application document folder

https://iosdevcenters.blogspot.com/2016/04/save-and-get-image-from-document.html

3) You need to write code to delete the existing image otherwise app size will increase.

Delete files from directory inside Document directory?

4) Get image from Application document folder and add it to your view as background.

https://iosdevcenters.blogspot.com/2016/04/save-and-get-image-from-document.html

Community
  • 1
  • 1
Jasmeet Kaur
  • 1,538
  • 14
  • 16