UIImageView tintColor colors whole image - ios

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.

Related

RerfreshControl background does not cover

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)

CGRectIntersection setting colour

I'm using this code here to create a view with a transparent area.
https://github.com/heigong/PartialTransparentMaskView/blob/master/src/PartialTransparentMaskView.swift
The issue is that the intersection is black even though the colour is set to UIColor.clearColour()
My code for creating this view is below
let view = PartialTransparentMaskView(frame: self.view.bounds, backgroundColor: UIColor.blueColor(), transparentRects: [self.testView.frame], transparentCircles: nil)
self.view.addSubview(view)
How this looks is also below
The area in the black is set to UIColor.clearColor() so I genuinely have no idea why it would be appearing black.
Any help would be appreciated thanks.

remove searchbar black border

I have a search bar that looks like this:
Is there anyway to remove that black border on the top?
I tried the minimal bar approach but got:
So the border was removed but now I would need to somehow color the inner field white.
I tried:
if let searchTextField = searchBar.valueForKey("searchField") as? UITextField {
searchTextField.backgroundColor = UIColor.whiteColor()
}
But it didn't seem to change anything.
I'm looking for a solution to either of these problems. I just want the pink border with the white text field.
Edit:
There is a similar question for iOS7 but the accepted answer did not work for me.
Creating an image filled with the pink color:
And setting it as the backgroundImage for the search bar did the trick.

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)

Monotouch UIView Appearance changing UITextField background colors, UIButton background colors, etc

I am trying to implement a custom appearance for UIView when contained in UIViewController.
var viewStyle = UIView.AppearanceWhenContainedIn(typeof(UIViewController));
viewStyle.BackgroundColor = UIColor.Blue;
The result I get from doing this is something ugly, like this:
I tried adding code to change the UITextField/UIButton background by doing:
var txtBoxStyle = UITextField.AppearanceWhenContainedIn(typeof(UIViewController));
txtBoxStyle.BackgroundColor = UIColor.White;
var btnStyle = UIButton.AppearanceWhenContainedIn(typeof(UIViewController));
btnStyle.SetTitleShadowColor(UIColor.White, UIControlState.Normal);
btnStyle.SetTitleColor(UIColor.Black, UIControlState.Normal);
but that doesn't help my result at all (the above image isn't updated from when I changed the button title color from white to black, you'll have to imagine the button's text as black instead of white). Anyone know how to get rid of that ugly blue in the (foreground or background?) of the UITextFields and UIButtons? Bonus if you can figure out why the Title's background is blue as well and how to fix that!

Resources