I am checking my app with ios 7 beta. I have set background color of UITableView to clear color. Its still showing white background.
Is there any other way around to make it transparant?
I couldn't make it work but the following worked perfectly :
-(void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
}
Setting tableview backgroundColor to clear color working absolutely fine in iOS 7 chk screenshot see those separator lines for the table cells while the tableview is transparent.
Believe it or not, the following statement, added to cellForRowAtIndexPath, will cause iOS 7 to honor the XIB-specified color:
cell.backgroundColor = cell.backgroundColor;
In my XCode 5 Storyboard I had to set the background color of the 'View' section on the Table View properties to clear as well.
Related
Xcode 6 beta 6, trying to change all UITableView's background colours in appearance proxy:
[[UITableView appearance] setBackgroundColor:[UIColor redColor]]
But seems that it doesn't work.
Steps to reproduce:
1 Create single view project
2 Add UITableView to ViewController in storyboard
3 Set delegates to view controller and change background in IB:
4 Add dynamic cell and configure data source:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:#"Cell1Identifier" forIndexPath:indexPath];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60.f;
}
5 In app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UITableView appearance] setBackgroundColor:[UIColor redColor]];
return YES;
}
6 Run app and watch incorrect colour:
Any suggestions how to fix it?
Setting background color for every table doesn't look like good solution.
try to "reset" the BackgroundColor to "Default" in the InterfaceBuilder (even if its already Default, you'll see a little color change)
this doesn't works with grouped style tableviews
UPDATE:
this worked for me
[[UIScrollView appearance] setBackgroundColor:[UIColor redColor]];
Clear color for TableViewCell not working in Tablet in XCode 6. The following workaround solve for me.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
It appears that for iOS 8, at least for our circumstances, when we set a view's background color with a table in that view, we have to explicitly set the table and cell background colors to Clear in order for the desired color from the view to show. I suppose, with prior iOS versions, the cells were defaulted to transparent but that seems no longer the case.
Set cell background color to transparent in
tableView:willDisplayCell:forRowAtIndexPath:
[UITableVIew backgroundColor] is not marked with UI_APPEARANCE_SELECTOR. Appearance proxies will only work if selector is marked with UI_APPEARANCE_SELECTOR.
It seems that the appearance proxy exhibits a seemingly unreported bug in iOS 8.0.x; it's unrelated to the iOS 7 change involving the default background colour of table cells.
The relative good news is that this only seems to be an issue between iOS 8.0 and 8.0.2, because:
My iPhone 4S on 7.1.2 doesn't have this issue,
My colleague's iPhone 6 running 8.1 doesn't have this issue.
Until most users have upgraded you will have to set the background explicitly on the object itself, sending us back into the pre-appearance era :(
I have no experience with ObjectiveC, I am practising swift programming, my program works with no error.
In my detail View Controller I have added tableview and a tableview cell
When I run I check there is data come back but there is a strange grey cover over my table view as shown in following screenshot, I have tried remove table view and even View Controller it still come back. What I possibly done wrong or this is bug of beta version? I am using beta 5
below the code clear the tableview background color check attachment for example enter image description here
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
tableView.backgroundColor = [UIColor clearColor];
}
I am using UITableVeiw with static cells in iOS7. The table view looked like this before I converted my storyboard to use autolayouts.
I am using the "background view" property and the "selectedBackgroundView" property of the tableviewcell to set backgrounds like so:
After enabling auto-layout though in the storyboard, the layout goes bonkers and this is what I am left with:
I don't have any auto-layout issues that are presented to me. Just that I am not seeing the foreground and background anymore with auto-Layouts.
Any help?
Seems like the auto-layout was creating problems for me. I added the backgroundView and selectedBackgroundView programmatically and it works.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIView *selectedView =[UIView new];
selectedView.backgroundColor=[UIColor colorWithRed:0.604 green:0.812 blue:0.059 alpha:1.000];
cell.selectedBackgroundView = selectedView;
UIView *defaultView =[UIView new];
defaultView.backgroundColor=[UIColor colorWithRed:0.396 green:0.404 blue:0.404 alpha:1.000];
cell.backgroundView = defaultView;
}
I think it can be fixed in Storyboard but... the "solution" is totally stupid :D. If add width and height constraint to selectedBackgroundView it will works. This solution isn't good for me, but seems like it works :)
P.S. The way with adding selectedBackgroundView programmatically is work for me too.
I have a customized UITableView, the cells have a different background color (set in a custom backgroundView). However, the background color is only applied within the cell, but not extended to the inset area of the separator. As you can see in the screenshot, there is a white area to the left of the colored separator.
How can we change the color of this white line? We would like to make the line "disappear" by setting it to the same color as the cell background. Thanks!
Setting the cell's background colour to the same as the contentView's background colour seems to give the best results.
cell.backgroundColor = cell.contentView.backgroundColor;
That will handle cases where the accessoryView is the wrong colour as well.
So I just had this problem myself, and it's strange because it seems to work fine on some tableviews. I'm assuming that the grey color you are using is the background color of your tableview. If not, this solution may not work.
It seems like cells in iOS 7 don't always pick up the tableview background color when a separator inset is present, so you need to manually set the cell background to clearColor. Interestingly, setting this value in storyboards didn't work for me, I had to do it in code. Add this:
cell.backgroundColor = [UIColor clearColor];
when you configure the cell in this delegate function:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
It's the default in iOS 7. But you can change it to the way iOS 6 looks. Please try my code below. You will be amazed:
tableView.separatorColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
NSString *iosversion = [[UIDevice currentDevice] systemVersion];
int version = [iosversion intValue];
if(version>6)
{
tableView.separatorInset = UIEdgeInsetsZero;
}
Swift 3+:
tableView.separatorInset = UIEdgeInsets.zero
Use image for separator. This the only easy way to acechive your expected result. For ios 7 in xib we have edge insect property is there you can use.
Go to storyboard > Attribute Inspector > Separator Insets, then select cutom and change left coordinate from 15 to 0.
it will be Done.
In Interface builder on the UITableViewCell set the attribute 'background' to be clear (or whatever) and then on the Content View set the attribute 'background' to be clear as well and the problem should go away.
This is the only method that worked for me... (separator = None via storyboard)
I had similar issue and below code worked like charm.
[self.tableView reloadData]
reload tableview on didSelectRowAtIndexPath Method.
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView reloadData]
}
only this fixed my issue.
I have a custom grouped UITableViewCell, with a couple of UILabels on it. Since the UITableViewCell background color used to be pure white, it matched the UILabels' default background color, so the UILabel box wasn't visible..
After updating to iOS 5.0, I notice that now the default background color for grouped UITableViewCells is a more greyish white (actually #f7f7f7), and as a consequence the UILabels' frame is visible in an ugly way..
So, what is the best way to set the UILabels' background color when it needs to vary between different iOS versions? I know I could use opaque = NO and [UIColor clearColor], but I would prefer to paint the UILabels' background for performance reasons.
In the delegate method tableView:willDisplayCell:, the UITableViewCell will have the background colour set to white or, in iOS 5, greyish.
You can change all your the backgroundColor of all your subviews.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (UIView* view in cell.contentView.subviews) {
view.backgroundColor = cell.backgroundColor;
}
}
Nothing wrong with gcamp's answer, but if you'd prefer to keep the background white on both iOS4 and iOS5, then just do this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor whiteColor]];
}
I saw that problem in my custom UITableViewCell in a grouped TableView I just set the label background color to clear and that fixed it for me and works in iOS4 and iOS5. I set this in the custom cell code where the UILabel gets created as below:
[nameLabel setBackgroundColor:[UIColor clearColor]];
After that problem gone.
You can call:
[[UIDevice currentDevice] systemVersion]
Although that is discouraged for a lot of reasons, and I'm not sure it's the best way to solve your problem. In principle, you should be able to deploy view code and get the consistent results you want by some other means.
If you do actually want to compare device versions, you'd probably set a property and check the device's OS when the view controller loads, as opposed to within your cellForRowAtIndexPath...
What I did was set the background color of the cell to [UIColor whiteColor] in willdisplaycell...
That way I control how things look.
its use UIColor.systemBackground but its available for IOS 13 Only
so use it likes this :
if #available(iOS 13.0, *) {
cell.backgroundColor = UIColor.systemBackground
} else {
cell.backgroundColor = .white
}