I'm getting an odd behaviour with UITableView that maybe someone can help me with.
I have a UITableView. I then do:
table.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tablebg.png"]];
cell.backgroundColor = [UIColor clearColor];
This works as expected, except I'm getting a strange white border along the right and bottom of the table (see image).
Any ideas?
Seems like the tableview isn't aligned with the very superview (view) edge. Make it a bit wider and taller. I would temporarily set the view background color to something else so that you can see where the table extends to.
It seems that your are using a PNG with alpha different from 0 and I have experimented the same issue with some images. Try:
table.backgroundView.alpha = 1.
Related
I have an AVPlayerController and have shifted it up 100px. The background of the video is solid white and the background in the app is solid white. Yet there's a weird flickering on the edge when it scrolls.
You can see the border right above the signup button and at the edge of the cell. I even tried putting a second view above it with a white stroke to hide it, and it just shifted it in more. The fact it's not a single color and instead flickers is super strange to me.
Any ideas how to fix it?
Video -
https://drive.google.com/file/d/1kBK92teYIm29_tAMFpMizdAMAVw8CknV/view?usp=sharing
As a quick solution, you can make screenshot of the video and put it on overlay view of the AVPlayerViewController while scrolling.
Edited: You can try to set overlay property as UIView with white background color and see if the gap is gone. It may looks like that:
UIView *overlay = [[UIView alloc] initWithFrame:self.myPlayerVC.bounds];
overlay.backgroundColor = [UIColor whiteColor];
self.myPlayerVC.contentOverlayView = overlay;
I'm setting the backgroundView of a tableView like this:
self.tableView.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"background"]];
It works but gets placed on top of the tableview's activity indicator and hides it when the tableview is pulled down for refresh. I've tried setting a breakpoint on the point it's added and confirmed that indeed it goes on top of the activity indicator subviews array. Is there any way to fix this?
Thanks in advance.
I suggest that is better to place UIImageView below your UITableView and set:
_yourTableView.backgroundColor = [UIColor clearColor];
This code works in iOS7, but when running in iOS6 simulator the cells who should be above the sublayer will instead be below them.
bgLayer = [BackgroundLayer gradientFromColor:COLOR_MID_GRADIENT to:COLOR_GRADIENT];
CGRect bottom = self.view.bounds;
bottom.origin.y = self.view.bounds.size.height-GRADIENT_HEIGHT;
bottom.size.height = GRADIENT_HEIGHT;
bgLayer.frame = bottom;
[self.view.layer insertSublayer:bgLayer atIndex:1];
What it does is to put a gradient-layer at the bottom of a view with a tableview.
However, the cells in the rect of the gradient will be hidden behind it!
I tried to change the index but it doesnt do anything. Also, insertSublayer: below: doesn't work either.
What am I missing? How to put the layer below the table view cells?
Thanks.
Thanks to trojanfoe I got pointed in the right direction.
I've managed to get it working with manually changing the zPosition for the conflicting layers. Though I have to run the add layer-code in viewDidAppear instead of viewWillAppear for iOS6. Don't ask me why, I guess it has to do with the rendering of the cells happening after viewWillAppear.
You mean below, as in "behind"? If so, set the backgroundView of the tableview , and modify it as you see fit. (layers, subvies etc) and it will always appear behind the cells
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.
In short, I need to restore the default backgroundView for a UITableViewStyleGrouped cell.
cell.backgroundView = ??;
The long story:
I have a grouped tableview with some cells. For every cell the user needs to select some value or do some input. After that he can proceed to the next ViewController by touching a "next" button.
Anyway, to indicate to the user that he missed something, I display a nice red border around the cell with the wrong/missing user input. I do that by setting the backgroudView of the cell with a custom image like this:
cell.backgroundView = myErrorIndicatingImageView;
The cell now looks like this (screenshot, ignore the stars and label)
So far so good, this works like a charm. But after the user corrects the input I want to remove my red border background image and just show the original background again. The original background looks like this (screenshot):
And this seems to be a problem.
I tried several things
// try by setting the background to nil
cell.backgroundView = nil;
this removes the background completely and I'm lost with a cell without background.
// try it with addSubview and later remove the subview again
[cell.backgroundView addSubview:myErrorIndicatingImageView];
this does nothing. The myErrorIndicatingImageView is not visible. Even a [cell.backgroundView bringSubviewToFront:myErrorIndicatingImageView] does not help.
Right now the only solution I have is to create a new UITableViewCell for every single call to cellForRowAtIndexPath. This works but is just bad code and ignores completely the technique to reuse cells.
There must be a simpler solution...something like
cell.backgroundView = [self.tableView getDefaultBackgroundView];
what about trying this:
cell.backgroundView = [[UIView alloc] initWithFrame:cell.backgroundView.frame];
Or you can make the background view as a UIImageView and set 2 images in problem and fixed
Assuming you are doing this with a custom table cell class, save the original backgroundView in some ivar, then apply the new background. When you want to reset the background, set the backgroundView back to the original, saved background view.