RerfreshControl background does not cover - ios

I'm trying to customize the refreshControl in my tableView. however when i pull down it seem to show a little white margin of the backgroundColor. Is there anyway beside changing backgroundColor to the same as refreshColor to avoid this? since by changing background Color it will be seen when i pull up and this won't be nice looking?
reloadControl.tintColor = UIColor.blackColor().colorWithAlphaComponent(0.4)
reloadControl.backgroundColor = UIColor.redColor()
reloadControl.tintColor = UIColor.whiteColor()
self.tableView.addSubview(reloadControl)

Related

Why can't I set tableview background color to white?

Whenever I do and run the app it's light gray. I've changed EVERY color I can and white just does not stay white. Every other color I've tried works, just not white.
I tried these 2
self.tableView.backgroundView = UIView()
self.tableView.backgroundView!.backgroundColor = .white
self.tableView.backgroundColor = .white
And I've tried to just set it in storyboard to white
I had this issue for reasons I can't fathom when setting the TableView's View background colour to white or a light-grey colour in the XIB file. Any other colour worked just fine. Only fix I found was to set the background colour to white in the UIViewController's viewDidLoad function like so:
tableView.backgroundColor = UIColor.white
You should create the view with the correct rect:
self.tableView.backgroundView = UIView(frame: self.tableView.frame)

Swift 4 backgroundColor bug?

I have a problem with transparency in my Views, especially with UITableView.
Just to make sure. I already have 3 years of experience with swift and this is the first time, I am getting this problem.
So in apple's docs it says the following:
backgroundColor
The view's background color.
Changes to this property can be animated. The default value is nil, which results in a transparent background color."
But when applying clear color to backgroundColor or tableView.backgroundColor = UIColor.clear, the background is still appearing white.
Is this a bug or a feature?
EDIT:
The tableView isn't the problem anymore. It is the cell within the tableView.
Already tried solutions are clearing the background color of all subviews. Nothing changed.
EDIT 29.09.17
Ok, I debugged my application and got this:
UICachedDeviceWhiteColor and cachedColor.
A google searching also didn't help.
Edit 29.09.2017 Later that day ...
The problem occurs, when updating from swift 3 to swift 4.
I made a new project with swift 4, but it actually works fine.
Because it is a problem I have to solve. I will try some things and update this post from time to time.
In UITableViewCell and UICollectionViewCell there is a property view called contentView.
A common mistake is to manipulate the cell directly. Instead try to manipulate the cells content view:
Obj-c
UITableViewCell *cell = ....// get the cell
cell.backgroundColor = ... // BAD !
cell.contentView.backgroundColor = [UIColor redColor] // this is the correct way.
Swift
let cell = ...
cell.contentView.backgroundColor = UIColor.red // make sure its the contentView
also a couple small nuances with colors and opacity:
If you want only the background to have opacity (i.e. less than 100%) , make sure you are not changing the view's opacity (i.e. view.alpha = 0.5 BAD) - change the color's opacity value instead:
i.e.
cell.contentView.backgroundColor = [UIColor colorWithRed:... green:... blue:... alpha:0.5];
Another useful trick is to pause the application and press the "visual debug" button.
Search for your view and check it's attributes in the inspector
Found the problem:
When instantiating a variable which holds the view before displaying it, the background color of this view is white. The debugger calls this UICachedDeviceWhiteColor.
Why would you do that?
If you instantiate the view before it is displayed, you can switch with a menu between different views very fast with "bringSubview(toFront: ...).
How to fix:
To fix this you have to instantiate the view every time you want to show it.
Hope I could help some lost souls with this answer and Apple is going to fix this bug.
Verify that the view behind it is not white, then set the current view's (the one with the transparent background) modalPresentationStyle to overCurrentContext. This will allow views behind to show through the UIColor.clear background color.
If you are setting
tableView.backgroundColor = .red
and if it's an empty TableView then the Red will be visible. I give a headerView and FooterView also to visualise.
Now TableView Contents some data, so to reflect the color you need to set background color to cell.
class UserCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundColor = .yellow
}
....
}
You can check out the original project here.

UIImageView tintColor colors whole image

I've tried changing the tintColor of a UIImageView inside a UICollectionViewCell after a tap by setting render mode of the icons to Template Image and then setting the color by calling
iconView.tintColor = .blue
Problem: This fills the whole image with the chosen color, Instead of just changing the non-transparent parts.
This method has been working for me in the past, and I'm unable to figure out the problem. I assumed that the icons might have a white background instead of a transparent one, but that's not the case. Maybe it has something to do with the UIImageView being inside a UICollectionViewCell?
Help would be highly appreciated!
try this
imageViewHome.image = UIImage.init(named: "yourImageName")?.withRenderingMode(.alwaysTemplate)
imageView.tintColor = .blue
The following code will color only the non transparent area.
yourImage.image = yourImage.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
yourImage.tintColor = UIColor.redColor()
Happy coding.

UITableView set seperatorColor with clear background color

I have a UITableView with backgroundColor = UIColor.clearColor().
In my tableView I've got cells with different backgroundColor. Some of them have a clearColor background as well. Now I want to set a general color (not clearColor) for the seperatorLine which doesn't seem to work with a clear tableViewBackgroundColor.
If your intention is to get rid of the separator, you can do that like this:
tableView.separatorStyle = UITableViewCellSeparatorStyle.None
To me this more clearly describes what you're trying to do.
ok! I am an idiot....
I didn't see that I was setting
tableView.separatorEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
later in the code.... embarrassing

Not able to set tintcolor to image set as background in a tableview cell

I am facing trouble setting a tint color to my images which are set as background for my uitableviewcells.
The following is my code:
backgroundImage.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
cell.backgroundView = backgroundImage
cell.backgroundView!.tintColor = UIColor.blackColor()
The images are showing normally without any tint added to them.
Any help is really appreciated.
Replace the first line with this: backgroundImage.image = backgroundImage!.imageWithRenderingMode(.AlwaysTemplate)

Resources