One of my apps has three UIButtons on it, and they use images that I got from icons8. In the code, I change the tint color and it works fine. Whatever I set the tint color to is what color the button image becomes that color.
Today I wanted to add a fourth button to mute sound. I downloaded the images that I wanted from icons8, added the button and set it up like I have the rest of the buttons set up. The new button is not changing colors like the rest of them. I'm certain that it has to do with the image, because if I select a different image, it changes color. I also tried using the new image on one of the older buttons and it would not change color.
My question - is there anything special that needs to be done to an image to make it work with tint color?
Try setting the image to render as a template image. You can do this in your .xcasset folder selecting the image set, opening the attributes inspector and setting render as to "template image."
What I did was follow the #beyowulf instructions and on the code I just did this
yourBtn.tintColor = .white (or other color)
this worked for me
Related
I want to add special icon with 2 color in the tab bar but the app detect just one color I used lots of single color icons and there is no problem with them but this icon won't show as I want to be
here is the image of that Icon
the tabor background is white
try to use .jpg of the image in place of .png
If you are using image assets then change the render option as Original Image instead of Default.
Otherwise change the tint color of tabor to clear.
Try to set color you want using this code.
UITabBar.appearance().tintColor = .red
Or you can tell the system to keep the original rendering mode, so it does not use default colors. Set image like that.
... = UIImage(named:"myImage.png")?.withRenderingMode(.alwaysOriginal)
I am planning to make theme color of UI elements in application.
how we show custom color(Golden Color) like Black color in picker menu
is it possible? like we can add custom Property as shown in snapshot
You can add custom color as folow
Select color property(Background color, text color, etc.). A popup is shown from that select "other" option.
A color picker will be opened. Here you can set your custom color by RGB/Hex Code and you can set opacity.
The color will be applied and visible under "Recently Used Colors". This is how you can add custom colors but as far as I know you can't add colors in that default list.
Create a new palette by clicking "New" here:
A new palette "Unnamed" will be created. You can rename that palette by clicking the cog again and choosing "Rename..." Then, you'll need to click on the objects you want to capture the color of, and drag the color of those objects into the color chip area:
Once you've captured the color, you can even rename it something that indicates where it's normally used, providing more information to the recipient than just the color.
source
As of Xcode 9 you can add colors to your asset catalog.
Open your asset catalog, click the + and add a color set.
Click on the color that was created and you can name it and set the color using the inspector.
Thereafter that color shows up in storyboard color chooses in the area called Named Colors.
To achieve this follow these steps
*) In the Project navigator, select the asset catalog, click the Add button (+) at the bottom. In the pop-up menu, choose the type of asset set to create
*) then you'll see the color asset on storyboard.
Cheers :)
The bar item images I prepared are about 35*35
and I use the Sketch to export the [1x & 2x] size images;
(I can't insert any images for instances at here because of my zero reputation//Sorry about this!)
Then it displays a blue square :<
the function and title of Item is OK
BUT just the icons are wrong
Could someone tells me how to fix it!
Appreciate!!!
I figure it out!
There is nothing wrong with your code or setting
It's about your IMAGEs
You can just look at the apps on your phone.(almost)Any tab bar item icons are in gray.
So the Icon will just display their UN Hollow parts in gray!!
[Additionally,according to official API,they wrote like this:
By default, unselected and selected images are automatically created from the alpha values in the source images. To prevent system coloring, provide images with UIImageRenderingModeAlwaysOriginal.
]
Consequently the solution is : USE Sketch to make your instance's icon heart-part to be hollow
You need to add #3x image too.
Is there a way so that you can set both image and title of UISegmentControl simultaneously, so that image appear next to the title , just like image appear next to title in UIButton.
I am trying but if I set image of Selected segment of UISegmentControl then title disappears and if I set title of Selected segment of UISegmentControl then Image disappears, I want to set both at a time.
The official documentation for -setImage:forSegmentAtIndex: says
A segment can only have an image or a title; it can’t have both. There is no default image.
So, no, there is no way to do what you want using the image and title properties.
However, there are a few options to accomplish the objective in different ways.
if you are going to use the same image for each segment, you could use the appearance methods to set the background and then use the method -setContentOffset:forSegmentAtIndex: to move the title to the side of the background image.
you could create an image that had both the icon and the text in it. This is less than ideal as a change to the text requires exporting of the entire asset again. But is an option.
the least ideal would be to fake a segmented control using buttons that you write the code for to handle state changes. There may even be some open source options that do just that, so feel free to search for them.
I have been trying to figure out this problem for a while now and no avail. I have a program I inherited and it uses a a white background image for the buttons. You can change what image you want easily from UI editor. When the user presses down on that button the white background image is switched out for a different image, showing a blue highlight instead. For the life of me I can't find where that is being referenced at. I even tried adding a new button and it is the stock highlight color.
Where is that onPress reference probably at? Or where can I re-reference this new button to have a new onPress image background?
Thank you!
Select the button in Interface Builder. Open the attributes inspector for that button. Under Button you can choose the "State Config". Change that to "Highlighted". Now you can change the Image config for the highlighted state.