I have a UIImageView
that has a UIImage
.
What i would like is when the UIImage
is clicked the user can select a photo from thier gallery to show in the UIImageView
instead of the default image i have set
imageView = [[UIImageView alloc] init];
UIImage *myimg = [UIImage imageNamed:@"ProfilePic.png"];
imageView.image=myimg;
imageView.frame = CGRectMake(100,0, 80, 50); // pass your frame here
[setsView addSubview:imageView];
imageView.layer.backgroundColor=[[UIColor clearColor] CGColor];
imageView.layer.cornerRadius=20;
imageView.layer.borderWidth=2.0;
imageView.layer.masksToBounds = YES;
imageView.layer.borderColor=[[UIColor redColor] CGColor];
EDIT: If I could make a view with a bunch of images and when an image is clicked it changes the "myimg" to the clicked image if that makes sense
EDIT #2:Also how would u save the photo the user chose and use it the next time the user opened the appliation
What you need is to implement
UIImagePickerController
withUIImagePickerControllerSourceTypePhotoLibrary
as a source type.ThereĀ“re tons of tutorials and questions/answers here in stackoverflow.
Check for example this thread. It has pretty good answers with reference links to a sample code from Apple and other interesting tutorials.
EDIT #2: Well, this also has many ways to be accomplished all depends on your use case. But a quick and simple way to do it is by using
NSUserDefaults
.Eg: This to save the image,
and to get the image