UITableView background color iOS 9 - ios

I have a UITableView that I want to set its background color to transparent. Background color for the table view and all subviews at interface builder is set to transparent. It works fine for iOS 8 & 7. but, not iOS 9. any idea?
cellForRowAtIndexPath method:
[cell setSelectedBackgroundView:[[UIView alloc] init]];
[cell.selectedBackgroundView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
[cell.contentView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:[[UIView alloc] init]];
[cell.backgroundView setBackgroundColor:[UIColor clearColor]];

Objective-c:
[self.yourTableView setBackgroundColor:[UIColor clearColor]];
Swift:
self.yourTableView.backgroundColor = .clear
XCode 7.0 bug. Not picking up from Storyboard

This happens to me even when creating an UITableView in code, and setting it as a private property of my UIViewController. However, if the UITableView is a global variable, this problem does not occur.
I suspect Apple is rooting around the ivars on my UIViewController, setting UITableView's background colors to UIColor whiteColor without asking me. I have checked, and the calls to do go through setBackgroundColor on the UITableView.

Related

How to create Transparent background for UITableView and UISearchBar

In my application i added one UITableView and UISearchBar and its background by default white color. I would like to change the background of both items to clear or transparent, For that i tried to change the background colors .
tableview.tintColor=[UIColor clearColor];
srchbar.tintColor=[UIColor clearColor];
But its not affect on UI. How to do it properly?
The UI screenshot given bellow .
For TableView
[self.yourtableView setBackgroundView:nil];
[self.yourtableView setBackgroundColor:[UIColor clearColor]];
And asign clear color to cell
cell.backgroundColor = [UIColor clearColor];
And for UISearchBar
[self.yourSearchBar setBackgroundColor:[UIColor clearColor]];
[self.yourSearchBarsetBackgroundImage:[UIImage new]];
[self.yourSearchBar setTranslucent:YES];
For iOS7+, all you need to do is:
[self.searchBarHome setBackgroundColor:[UIColor clearColor]];
[self.searchBarHome setBarTintColor:[UIColor clearColor]]; //this is what you want
as written in Make UISearchBar background clear

Globally set background color of buttons, except accessory buttons in UITableView

I am using the below code to make all my buttons in an application the same color. However the accessory icon in the UITTableView row also has it. Is there a way to ignore it in the table view?
[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];
A UIView conforms to the UIAppearanceContainer protocol.
So you should use appearanceWhenContainedIn: to distinct buttons depending on where they are contained in.
[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];
[[UIButton appearanceWhenContainedIn:[UITableView class], nil] setBackgroundColor:nil];
It would be best to use the UITableViewCell subclass instead of the table view.
You can use the
[[UIButton appearanceWhenContainedIn: [UITableView class]] setBackgroundColor:[UIColor differentColor]];

cannot set background color of UITableViewCell in iOS6?

I started testing my app under simulator, because I don't have any iOS 6 device and stumbled upon weird problem. I cannot set backgroundColor property of UITableViewCell. If I st this:
cell.contentView.backgroundColor = [UIColor redColor];
it is working only for iOS 6, when I use this:
cell.backgroundColor = [UIColor redColor];
or this
[cell setBackgroundColor:[UIColor redColor]];
it is working only for iOS7.
When I use both cell.contentView and cell.backgroundColor it's working for both iOS... shouldn't it be one answer for such a 'easy' property? Or maybe it's some simulator bug?
UPDATE:
If it changes anything in the same tableview and cells I cannot set accessoryType neither via StoryBoard nor code...
UPDATE2: for some reason setting tableview style to plain deleted all my changes, but grouped showed as expected...
In iOS6 you need to change the cell's backgroundColor in willDisplayCell.
This works in iOS7 as well, precluding the need for version-specific code.
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor redColor]];
}
I don't see the problem in setting the background for the contentView AND directly to the cell. iOS 7 has change a lot this class. If you need to be compatible with old systems then you need to do this type of things.
So yes, you should use both:
cell.contentView.backgroundColor
cell.backgroundColor
Try to change the cell's backgroundView color not the backgroundColor.
UIView *myView = [[UIView alloc] init];
myView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = myView;
If you set (assuming you use standard cell):
cell.textLabel.backgroundColor = [UIColor clearColor];
...then you just have to use:
cell.contentView.backgroundColor = [UIColor redColor];
iOS 6 seems to copy table's background color to textLabel.
try to add this code:
cell.backgroundView.backgroundColor = [UIColor clearColor];

UIAppearance proxy problems with appearanceWhenContainedIn

I am trying to give each label in my background view a shadow:
[[UILabel appearanceWhenContainedIn:[MyBackgroundView class], nil] setShadowColor:[UIColor colorWithWhite:0.6 alpha:1]];
[[UILabel appearanceWhenContainedIn:[MyBackgroundView class], nil] setShadowOffset:CGSizeMake(0, -1)];
The problem is that in my background view there are some subviews (a tableview for example) which cells' labels should not get this shadowColor.
I tried this by doing so:
[[UILabel appearanceWhenContainedIn:[MyBackgroundView class], nil] setShadowColor:[UIColor colorWithWhite:0.6 alpha:1]];
[[UILabel appearanceWhenContainedIn:[MyBackgroundView class], nil] setShadowOffset:CGSizeMake(0, -1)];
[[UILabel appearanceWhenContainedIn:[UITableViewCell class], nil] setShadowColor:[UIColor clearColor]];
But the text-shadow still exists in the tableviews' cells.
Can anybody tell me what I am doing wrong?!?
You can't use the UIAppearance proxy to customise UILabel at all. See this question. Attempting to do so, in my experience, leads to inconsistent and confusing results.
(I also saw the problem where setting appearanceWhenContainedIn:[somethingElse] on UILabel causes all other [UILabel appearance] calls to be ignored)
I would create a sub class of UILabel and set the shadow appearance on that.
I think you have two options:
You could enclose that modified controls in own container and use:
#implementation ChildViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[UILabel appearanceWhenContainedIn:self.class, nil] setShadowColor:[UIColor colorWithWhite:0.6 alpha:1]];
[[UILabel appearanceWhenContainedIn:self.class, nil] setShadowOffset:CGSizeMake(5.0, 5.0)];
}
#end
Changes will be applied only to UILabel instances hosted within ChildViewController container
Or you could subclass UILabel as suggested to avoid chaining appearance changes within your current container (so other labels in e.g. in cells are not affected).

ios 5 shows white font on textView

I have a textView, in an ipad app, im using the following,
self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(25, 73, 665, 85)] autorelease];
self.textView.delegate = self;
[self.textView setTextColor:[UIColor blueColor]];
[self.textView setFont:[UIFont systemFontOfSize:18.0f]];
//[self.textView setTextColor:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1]]; //color
//self.textView.textColor =[UIColor grayColor];
[self addSubview:self.textView];
it shows the right font color on ios 4, but on ios5 the font goes WHITE???
why?
ios4
ios5
how to fix this?
thanks!
Theres nothing in the code you provided that would indicate the textView turing text White. There must be some other method you are not including that is setting this text white. I would do a search for white throughout your project to see if the color is getting set somewhere else. Also, I would check Interface Builder to see if theres any indication of the text being changed to White.

Resources