I´m build a swipe feature for my todo-list application. When a user swipes(drag) the cell horizontally I would like to display a background image that covers the gap between the screen edge and the cell edge.
When I add an image to the imageView-property it just follows the cell. Can I somehow fix it to cover the whole background?
It sounds like you want to make something like Clear.
What you will need to do is:
Subclass UITableViewCell
Add your image view like this..
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.image = myImage;
[self insertSubview:imageView atIndex:0]; //I'm not at a compiler, so I'm not 100% on this, but it's something like this.
Add a UIGestureRecognizer to handle gestures, and set up dragging and appropriate actions.
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
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 using a simple code to add some images to my UIScrollView. Also I've implemented another code to detect touches on each image.
Here is the code:
(void)handleSingleTap:(UIGestureRecognizer *)sender
{
int senderTagIs;
senderTagIs = sender.view.tag;
if (sender.view.layer.borderColor != [UIColor cyanColor].CGColor) {
sender.view.layer.borderColor = [UIColor cyanColor].CGColor;
UIImageView *showFullImage = (UIImageView *)[self.view viewWithTag:sender.view.tag+100];
[showFullImage setTag:sender.view.tag+200];
[self.view addSubview:showFullImage];
showFullImage.hidden = NO;
NSLog(#"Show tag is: %i", sender.view.tag);
}
else
{
sender.view.layer.borderColor = [UIColor whiteColor].CGColor;
UIImageView *hideFullImage = (UIImageView *)[self.view viewWithTag:sender.view.tag+200];
[hideFullImage setTag:sender.view.tag+100];
hideFullImage.hidden = YES;
NSLog(#"Hide tag is: %i", sender.view.tag);
}
}
The above code, sets the border color to cyan and show my small images from UIScrollView, in another UIImageView.
But my problem is, that I can't set the option to hide all images and set border color white for all images when one image is touched.
Ex: If I touch the first image, then the code will work, my big UIImageView will show touched image and touched image from UIScrollView will get the cyan color for border, so far so good.
Now, If I touch third image, my first image is shown, the color border is cyan, and so... I have to touch first image again to disable, but this is not what I want.
So, we've got a few things going on here. First, I'm assuming you're trying to show a collection of images in a scroll view with some custom padding to indicate selection around them. This sounds tailor make for using UICollectionView with a custom cell.
Absent further information, you're not resetting the old color. Either keep a reference to a selected image as a class variable or, assuming your image views are in a collection object like an NSArray, begin your method by iterating through the objects and resetting their view to an unselected state.
If you just need to hack together a solution, the second option should work. I really recommend using UICollectionView. It's a bit more work in the beginning, especially if you're not experienced with it, but it's well worth learning. Here's a good tutorial on UICollectionView.
I have a really large image that I want to use as a background image of a view. However, I don't want to display the entire image at once; I want only a part of the image to be displayed, and then I want to animate it to display other parts of it, similar to the "infinite background" in games (only not infinite in my case ;)).
What is the best way to do this? Will I have to separate the image in several pieces and then somehow animate the transition between the pieces, or is there a better way?
How about having UIScrollView as a background view? You can then put UIImageView inside that scroll view and control scroll view's contentOffset as needed.
I found the solution. This piece of code does the magic:
self.backgroundImageView = [[UIImageView alloc] initWithFrame: self.view.bounds];
self.backgroundImageView.image = [UIImage imageNamed:#"background.png"];
self.backgroundImageView.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview: self.backgroundImageView];
The key was setting the contentMode to UIViewContentModeBottomLeft.
I have a XIB file with UIControl and UIScrollView elements inside of it. I would like to add a background image to the view. I tried adding an ImageView in IB but I could not get it to be present as a background and it obscured the control elements. Sending a sendViewBack message doesn't seem to do anything either.
When I create a UIImageView programmatically, it doesn't show up.
Below is the code I attempted:
Programmatic Creation
UIImage *imageBackground = [UIImage imageWithContentsOfFile:#"globalbackground"];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:imageBackground];
[[self view] addSubview:backgroundView];
[[self view] sendSubviewToBack:backgroundView];
Dealing with the NIB file
[[self view] sendSubviewToBack:background];
where background is an IBOutlet declared in the header file and connected to the NIB's image view in IB.
Is there a step I'm missing here?
Set the frame and dont use sendSubviewToBack:. If you are working with UIImageViews you have to use [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"imageName.png"]];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"imageBackground"]];
backgroundView.frame = self.view.bounds;
[[self view] addSubview:backgroundView];
hope this was the deal.
Don't add the image view as a subview of the scroll view, it needs to be a separate view at the top level of the hierarchy, then sent to the back of the Z-order.
You will need to set the background of your scroll view to [UIColor clearColor], and ensure that the scroll view is not marked as opaque. You can do this in code or in interface builder.
Don't use imageWithContentsOfFile and then just pass it a filename with no extension (I'm assuming .png) - this is probably returning nil. Use imageNamed: instead (you don't supply an extension in that case, iOS4 and above)
Depending on the nature of your image, you can also generate a colour with it and use that as the background colour of your scroll view. I'm assuming self.view is the scroll view:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"globalBackground"]];