im trying to make a menu like FIFA app but i can't put the tableview in a transparent color,so the background image can be visible, can anyone help me?? I've tried of everything, any of this answers worked for me: UITableView clear background so i really need your help.
In addition to setting the background color of the table view to clear, you have to set the background color of the table view cells. And that, at least in my experience, has been somewhat tricky and couldn't be easily done via Interface Builder (the storyboard or the xib).
So you have to set the background color on your cells directly. For example, during your tableView:willDisplayCell:forRowAtIndexPath: delegate method, you'd do something like:
cell.backgroundColor = [UIColor clearColor];
And as rmaddy points out, Apple documentation for that method states:
This method gives the delegate a chance to override state-based
properties set earlier by the table view, such as selection and
background color.
Related
Say I want to mimic this "Shut Down" blue-tinted button in the iOS Settings app using the new (as of iOS 14) cell content configuration options:
How would I do this in a way that would also allow it to be properly dimmed if a user presented, say, an alert controller over top? For the unaware in this case it "dims" all the interactive/tinted views like this one to a grey color. Here's an example where an alert controller is shown over a grid of UIImageView buttons with a normally blue tint where you can see they're grey due to the action sheet:
But with cell content configurations, at least the default one, the only option I get for changing text color is via textProperties.color = ..., and since this isn't technically a "tint" (and there's no tint option I can see) it remains blue even when other views properly dim.
How do I fix this?
I tried reading the value of tintAdjustmentMode in the updateConfiguration method of the cell subclass, but it's not called for tintAdjustmentMode changes. I then tried calling setNeedsUpdateConfiguration() manually when tintColorDidChange() is called on the subclass, but that causes a brief delay in the color changing which looks bad/out of sync with other views.
Is there a way to do this that I'm missing?
One of iOS 14's changes included changing the UIPickerView to have a light gray selected row tint color. I was wondering if there is any way to change this or even access this property. I looked in the storyboard's attributes inspector and there didn't seem to be anything. Same with the code, autocomplete didn't bring up any selected tint related properties. Also looked around the internet but since it is a relatively new feature there wasn't anything helpful. Before iOS 14 I could put a UIView with my chosen color underneath to simulate this, but this update takes that away as the gray is still visible, and it looks bad. Here's a pic:
https://i.stack.imgur.com/BmoNO.png
I was wondering if there are any real ways to do this.
Also, a good solution would be to disable the light gray, because then I could use the strategy I show above. Any tips?
Without more information I can't say for sure, but in your View Controller class, access the UIPickerView and you can change it's tintColor and isOpaque properties. Something like this I would imagine.
pickerView.isOpaque = false
pickerView.tintColor = .clear
I looked into subviews. On delegate of a UIPickerView, within method didSelectRow I was able to set background.
pickerView.subviews.last?.backgroundColor = .clear
I have a xib. I have a view controller that loads the xib and adds it to its subview. The xib has the background color set from the xib file (from interface) to a CUSTOM COLOR SET from assets (created by me).
Everything works fine.
Now, inside my view controller, in viewDidLoad I want to override that background color with something else. The problem I found and it replicates 100% is that overriding doesn't do anything, unless I do it in viewDidAppear.
So to sum up...
custom color background set from xib... overriding in viewDidLoad not working, overriding in viewDidAppear working
Xcode default color background set from xib (any other color except from assets custom colors)... overriding in viewDidLoad WORKS...
Why in the first case I cannot override the color and in the second I can?
Is there a hidden feature that I'm missing here? You simply cannot override a view background color in viewDidLoad if the color set from xib is custom color, but if it's any other color... like white, red, black or w/e Xcode already has everything works as expected.
If it has any impact... this view controller I'm talking about gets pushed on the navigation stack. But I don't see how this can have any impact.
Reproduction Steps:
To replicate this... create a new sample project... that only has one view controller in it. Next add a custom color via assets -> new color set. Set the view controllers view background color from storyboard to the newly added color set. Then inside viewDidLoad change the background color of the view to something else... you will notice if you run the app it WON'T CHANGE if in storyboard there is a custom color set as background.
Somehow the background custom color set from storyboard overrides happen behind the scenes after viewDidLoad and before viewDidAppear.
I come late but have more info for future readers.
I just met this bug in my App for iOS 11 and iOS 12. The bug is solved by Apple since iOS 13.0.
So if you support previous version, you still need to apply the workaround from #AlanS, or not use custom colors in storyboard and xib :
func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
if #available(iOS 13.0, *) {
// Fix iOS 12 storyboard color bug.
} else {
view.backgroundColor = UIColor.black
}
}
Faced with this issue recently
I had xib file for table cell and custom colors in xcasset.
Colors are single appearance (dark mode not supported).
In cell swift class I have bool variable with didSet, where few outlets are modified: view.backgroundColor and label.textColor. Their values are based on variable value. There are ternar conditions so I was sure that color will be selected correctly.
On devices with iOS 12 (checked on 12.1 and 12.4 real and simulators) color didn't change at start but only after cell reuse.
After finding this question and few experiments, I have found that:
Setting custom color in xib file (no matter, if they have dark version or not) was performed after my didSet block and overrides my conditions results. And since I have set one of possible color in xib, I though that problem in data.
So I have reset outlets colors to default in xib and now it works
In case if you have to display some default color before some conditions, I guess putting it in init methods (awakeFromNib, viewDidLoad etc) should work
This bug was fixed in 13.0+
Duplicating answer from https://developer.apple.com/forums/thread/649009
One more strange workaround that helped me is to perform color updating code on the main thread.
It worked both in viewDidLoad and awakeFromNib.
DispatchQueue.main.async {
self.setupColors()
}
func setupColors() {
//your colors updating logic//
}
Storyboard is causing to me a lot of problems! :(
Now I'm trying to put an image as a background of a tableview in iOS.
I've done a png image with transparency in photoshop and I've imported it into my project.
** The first question is: is it possible to set the image background in storyboard?
I thought that a good idea was to create and image view and put it on my table view... but storyboard doesn't allow my to do this.
** I've also tried to add the background image via code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"table_background.png"]];
...
}
I obtained an horrible result with a black background instead of white, even if the png is transparent!
Moreover I've read that to optimize performances, it should be better to avoid transparent background for cells.
So, what it the best way to set an image as a background for a table view with storyboard?
Thank you in advance,
yassa
I think you have a method to set a background view for a tableView
[ tableView setBackgroundView:<#(UIView *)#> ];
And then add an UIImageView (but only for 3.2+)
Avoid using backgroundColor for this kind of things ^^
Using only story board I don't know :-] but with this method it should work.
Btw check that your tableView & cell have a clear backgroundColor, may be the problem too.
Good luck.
does anyone know why, if I add an image UIImage as background, I can clearly see it behind my grouped table view in Interface Builder.
However when I launch the app, the background is not showing at all, both in simulator and device.
Apart from adding the image, I suppose I already did all the steps at TableView programmatic side:
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
self.tableView.backgroundView = nil;
thanks
Following a post I made, I found two possible solutions, one with UIViewController in place of UITableVIewController as discussed here:
UITableView with fixed image background
with a disadvantage of header and footer problem with grouped table.
The other solution, involves writing more code and could be the case only if you have a common table that you share within different views of the apps: basically is to have a UIViewController calling a UITableViewController and attach its subview to self.view.