I'm currently making a photo decoration app. The *holderView is the sticker that has been chosen by user. Whenever I try to load a photo from photo library or take a photo and then load back to this page, additional *holderView added programmatically, which is the sticker that I've previously chosen before taking a photo, duplicated sticker appears after that, which is not what I want it to be.
How should I write the code for not letting this happen?
Thanks a lot.
- (void)viewWillAppear:(BOOL)animated {
UIView *holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, _imagePicker.selectedImage.size.width, _imagePicker.selectedImage.size.height)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:[holderView frame]];
[imageView setImage:_imagePicker.selectedImage];
[holderView addSubview:imageView];
...
}
Your problem seems to be that your using the viewWillAppear method instead of the viewDidLoad. This will cause multiple "imageViews" because your adding a new one every time you hide then show the viewController it's presented in. what you want to do is move the creation of the imageView (if there really is suppose to only be 1) to the viewDidLoad method and make that imageView accessible to the entire class, then in the viewWillApear simply change the image inside the imageView to the newly selected one.
Related
I am Using Circular slider in three classes. where i have three different Slider images and i want to add Circular Slider view (which is inherit from UIVIEW) on uiimageview.
This is my code:::
CircularSliderView *sliderView = [[CircularSliderView alloc] initWithMinValue:0 maxValue:100 initialValue:0];
sliderView.backgroundColor=[UIColor clearColor];
sliderView.frame=CGRectMake(88,160, 140, 150);
[self.view addSubview:sliderView];
It is not Working. if i adding it on Main view. it is working Properly.
I really don't know how it is going like this,please help me out!
if you are adding sliderView in self.imageview
[self.imageview addSubview:sliderView];
then write
self.imageview.userInteractionEnabled = true
By default UIImageview user interaction is disable
i hope this will work
I'm using UIRefreshControl to refresh data.
When I scroll upper, it refreshes data.
But I want to set refreshing view to my own custom image.
What I'm looking for is that purpule position
I want to set my own image at that section.
I don't know how that position is called so I couldn't search properly.
Just create an instance of UIImageview and add an image as a subview to the refresh controller.
UIImageView *imgview= [[UIImageView alloc] initWithImage:[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:imgview atIndex:0];
I'm having a few issues with displaying a UIImage in an app that I'm developing. The steps I took to do this are as follows:
1 - Add a UIImageView to my main view controller in the storyboard. I did this using the interface builder.
2 - I then created an IBOutlet for the UIImageView in the viewcontroller.h. I ensured proper referencing of the image view from the outlet.
3 - I set the image for the UIImageView like so:
_fireIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"flame_icon.png"]];
This was done within the viewDidLoad method in the viewcontroller.m file.
Troubleshooting:
I checked whether the _fireIcon variable is being set. It is.
I checked whether the viewDidLoad method is being called. It is.
In addition, the image is displayed when I statically set it via the storyboard itself. But when I do it via code, it does not display.
Let me know if you need any more additional information, or code snippets.
you need not to initialize an imageview as you are using Interface builder for image view
_fireIcon.image = [UIImage imageNamed:#"flame_icon.png"]; // or [_fireIcon setImage:[UIImage imageNamed:#"flame_icon.png"]];
This sets the image.
When we drop the UI elements using Interface builder , we need not initialize them, as they are taken care by apple.
Doing this you reset your property with newly created UIImageView:
_fireIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"flame_icon.png"]];
And your reference to UIImageView from storyboard gets compeletely lost.
Instead you want to set image:
_fireIcon.image = [UIImage imageNamed:#"flame_icon.png"];
Firstly, you do need to allocate the Element created via Interface builder, you just need to set the image to UIImageView directly like this :-
[myImage setImage:[UIImage imageNamed:#"5.jpg"]];
Make sure image name is correct and its extension too. I just tried and its working great here. Let me know if you still face problem here.
Swift 3.0
statusImageView?.image = UIImage(named: "select.png")
Im a beginner in programing iOS, so I have 2 questions:
1- I have a UIViewcontroller which load a few uiview and user is able to move them via touch. Now I want to put an image background in this way:
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"board.png"]];
[self.view addSubview:backgroundView];
But the image covers over all uivews!!
2- As I said, I move my uiviews by touch and when they have collided in the end touch they both goes in a folder, and a folder is created. So I want to know how I can make that a special image shows on the created folder ??
if (view != toMove && CGRectContainsPoint(view.frame,toMove.center)) {
viewToBefolder = view;
}
You can add your background view first, and then the rest of the views you add will be on top, or just do this:
[self.view sendSubviewToBack:backgroundView];
If your image view is covering the the background, you should be setting the size and position of the image view, or setting the constraints so that it is added at the size and position that you want.
Set your imageview into the main window.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]];
[self.window addSubview:backgroundView];
[self.window sendSubviewToBack:backgroundView];
Then set all your view controller view clear color. so, By default it's always display background image view into the all view.
I'm trying to use the page control feature along with UIScrollView to display a set of images on my IOS app, i've seen some tutorials but they all show how to change colors, how can i have some images loaded and use page control to go through them?
-(void)loadScrollViewWithPage:(int)page;
{
UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(scrollView.frame.size.width*page, 200, scrollView.frame.size.width, 100)];
img.image=[UIImage imageNamed:[viewControllers objectAtIndex:page]];
[scrollView addSubview:controller.view];
}
viewControllers stores the name of the image that you have taken.
Using PageControl, you can navigate through views, so you can put imageviews on the view and set the images on imageviews.