Background colors in UITableViewController with UISearchbar - objective-c

please look at the following screenshot.
It shows a UITableviewController with a UISearchdisplayController in the view header. I have set the background color of the table view to a somehow white color (see the below area). However the area above the UISearchbar does not have the same color (gray). How can I set / change this color? I tried different approaches like:
Adding additional subview
Seachbar background color
...
But till now i have had no success. Can anybody help me? Thanks in advance.

So i found the issue:
I was using:
self.tableView.tableViewHeader = self.searchDisplayController.searchbar;
Now I am using an aditional view with the searchbar as subview:
UIView *v = [[UIView alloc] initWithFrame:self.searchDisplayController.searchbar.frame];
[v addSubview:self.searchDisplayController.searchbar];
self.tableView.tableHeaderView = v;
Everything works fine now, the gray color is gone and the backgorundColors are equal.

you can play with
[[UISearchBar appearance] setBarTintColor:[UIColor redColor]];
or
[[UISearchBar appearance] setTintColor:[UIColor greenColor]];

Related

UISearchDisplayController with ViewController issues

I have a ViewController with a Navigation Controller before it, that has a TableView and other elements inside. The tableView has also a Search Bar, and in the scene, besides the main ViewController I have a Search Display Controller.
The functionality is working, but I have the following UI issues:
Although my main view has black background colour(and most of the elements have black background colour), when I drag the tableView downwards there appears some white space.
I also have the following initial setup for UI
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor blackColor];
self.tableView.backgroundColor = [UIColor blackColor];
self.searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.searchDisplayController.searchResultsTableView.separatorColor = [UIColor blackColor];
self.searchDisplayController.searchResultsTableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 12);
[self.searchDisplayController.searchResultsTableView setBackgroundColor:[UIColor blackColor]];
[self.searchDisplayController.searchContentsController.view setBackgroundColor:[UIColor blackColor]];
self.searchDisplayController.searchBar.barStyle = UIBarStyleBlack;
self.searchDisplayController.displaysSearchBarInNavigationBar = NO;
}
When I search for a result, and drag the table upwards after the Search Bar, there is a small place where the table view is visible.
Any ideas how can I fix this :(?
Edit update:
Both were solved removing the Search Bar from the TableView. After this another issue came that the animation of Search Display Controller wasn't updating the Search Bar. this was solved with the following post:
UISearchBar animation issue
You have to set UIView background color to black (not just UITableView color).
You have to position your table view below UISearchBar, you can do this either programmatically or via IB. I recommend second option. Pretty easy.

Objective-C NSScrollView Foreground Colour

I am getting into app development and just started using NSScrollViews to display large chunks of text.
I am able to set the background colour by writing the following:
[_HeadersScrollView setBackgroundColor:[NSColor darkGrayColor]];
But not set the foreground colour by doing something similar to:
[_HeadersScrollView setTextColor:[NSColor whiteColor]]; // nope
[_HeadersScrollView setForegroundColor:[NSColor whiteColor]]; // nope
[_HeadersScrollView setForeground:[NSColor whiteColor]]; // nope
Is there a method or any other way that I could get this type of setup to work? I'd really appreciate it.
The NSScrollView contains an NSClipView (a helper for scrolling) which contains the NSTextView. If you want to operate on the text view you either need an outlet to that or you can request the documentView from the scroll view.
You can do either:
[_HeadersScrollView.documentView setTextColor:[NSColor whiteColor]];
Or, if you have an outlet to the text view (called _textView in my example), you can do:
_textView.textColor = [NSColor whiteColor];
In this case, you would probably want to set the background color on the text view, too, rather than the scroll view. And tell it to draw its background by setting drawsBackground.
There is no setting like that for changing foreground color in scrollview.
_HeadersScrollView.tintColor = [NSColor whiteColor];
or
[_HeadersScrollView setTintColor:[NSColor whiteColor]];

Setting UITableViewCellStyle2 Tint Color

I can't believe I don't see this anywhere on Google, but I have an odd issue.
I am changing the Global Tint in iOS 7 in the App Delegate:
[[UIView appearance] setTintColor:[UIColor redColor]];
However, when I display a table view with UITableViewCellStyle2 cells, the text title color is still the default blue color.
Any ideas on how I could fix this? I'd rather not subclass it.
Thanks!
simply change the text color.
cell.textLabel.textColor = [UIColor redColor];

Custom View with UILabel in it appears black

I have created a custom UIView that has some set of UILabels in it. I add those UILabels inside the custom view inside its drawRect method.
But the whole custom view appears black on the screen. I have not set any background color for the custom UIView. How Do I fix this?
I tried setting background color to ClearColor but it still looks black.
I tried setting opaque property of the custom view to false and the view obviously disappeared.
Please help.
don't do that in drawRect: method which is intended to draw in the graphic context. If you want to add some specific subviews do it in an init / initWithFrame method.
For me the best way is to create a custom uiviewcontroller subclass and initialize it using a xib (nib) file. Working at controller level is a good practice.
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(10,0,320,35)];
newView.backgroundColor=[UIColor clearColor];
UILabel *mytext = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 28.0)];
mytext.backgroundColor = [UIColor clearColor];
mytext.textColor = [UIColor blackColor];
mytext.editable = NO;
mytext.text = #"Your label";
[newView addSubview:mytext];
[mytext release];
[self.view addSubview:newView];
[newView release];
Just incase someone stumbles upon this thread like I did in 2021. Check to see if you have accidentally toggled 'dark mode'. It will show similar visual 'issues' to the question above.

how to change the color of the tabbar controller

Is there any way I can change the Tab Bar Controller's color to something other than the default black? I know this isn't possible in IB, but perhaps maybe through code?
In AppDelegate
self.tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor grayColor];
In AppDelegate.m in didFinishLaunching... method write(this will change for whole app):
[[UITabBar appearance] setBarTintColor:[UIColor myColor]];
Or you can write in ViewController.m in method viewDidLoad:
[self.tabBarController.tabBar setBarTintColor: [UIColor mycolor]];
You can do with XIB/Storyboard as well as programmatically
For Xib/storyboard select tab bar controller than tab and you can see all the options to change tab bar or tab bar view properties see the attached image Image attached here
For programmatically:
for tab bar tint and background
[[UITabBar appearance] setTintColor:panelColor];
[[UITabBar appearance] setBarTintColor:[UIColor lightGrayColor]];