I have two image sets for "flag" button in my Images.xcassets: flag-highlighted and flag-normal, where each set has 3 images of size x1, x2, x3
I use the flag-normal image set for the Image attribute in the attributes inspector for this button. But, where/how do I specify the flag-highlighted image set for the selected state?
You can set image for specific button state via interface builder by using state config option.
Choose selected option and then pick your image for selected state.
If anyone is wondering why the state config is missing for button in xcode 13, you need to change button's style from plain to default after that state config drop down will appear and you can change it to whatever you want
Related
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 :)
My current long term project utilizes a palette of custom colors. In code, we are using a category to access these colors by name. This works great but there are times, such as when building a nib, that these colors won't be set programmatically.
I am looking for a way to define a named set of colors. For instance, when setting a background color for a UIView, I would like my drop list in Interface Builder to list my custom colors by name. Does anyone know of a way to achieve this?
Xcode 9
You now have another option to add Color Sets or Named Colors to your assets. This is new in Xcode 9.
1. Adding Named Colors to Your Project
In *.xcassets > right-click > New Color Set
2. Assigning Name Colors to Views
Your new Named Colors show up in your Color Picker now in their own section.
Custom Color Palette
In the Interface Builder's color dialog, choose the third tab. Click the gear and New to make a new custom color palette. You can name it whatever you want. Then click the plus (+) button to add a new color and name it. Use the color picker tool to set the color.
Colors from RGB or Hex
Choose the second tab in the color dialog and select RGB Sliders. This will allow you to set the colors using RGB or hex values.
More Help
XCode Tip: Color Palette
How to define colors in XCodes' Interface Builder?
How do I enter RGB values into Interface Builder?
Yes, you can create and edit a palette in IB and then share it with your team This article has all the details: http://natashatherobot.com/xcode-color-palette/
Edit:
That link has expired. You can see the web archive here: https://web.archive.org/web/20210303015055/http://natashatherobot.com/xcode-color-palette/
But, using named colors in the asset catalog is a better way to go now.
I am trying to set the toggle state of a UIButton through the interface builder. I have done it successfully using code, but I need to get it working through the interface builder.
Im not sure what the issue is but for selected I set its image to 'flashOn' and for disabled I set it to 'flashOff'
When I hold down the image, it shows the 2nd image, but pressing the image does not toggle between these two images.
Im certain it's super simple so if you can suggest what I am missing I would appreciate it
A button's selected and disabled states need to be set in code.
Can you show your implementation for when you got desired results through code? I think, from what I can piece together from your question, that you have mixed up the states of the button.
Default - images will display for this button in any state unless another is specified explicitely
Disabled - image will display when button is disabled. (button will not switch from this state through user interaction as it is disabled)
Selected - image will display when the button is selected, which as far as I know is only when you set the button as selected through code.
Highlighted - image will display when you press and hold down on the button
I know how to change the image programatically when a button is pressed, but there must be a way to do this non programatically in Xcode, but despite searching high and low I simply cannot see anywhere in Xcode where the selected image can be specified.
Try in your storyboard. The second selection (STATE CONFIG) down in attributes inspector should show "default" for your button. Change the sate (Highlighted, selected, disabled) and then change the image in the image box 8 down or background image underneath.
Open up the "Attributes Inspector" in your storyboard or XIB and the image name is an attribute you can set in your UIButton object.
Also make certain to make the "Title" empty or a string will be drawn over your image.
I want to add an image to my button instead of text. Can I do this in interface builder? Any example I can look at?
Thanks
Deshawn
1:select the button
2:select Attributes Inspector
3:change type to Custom
4:There are two ways to do this using the interface builder
-1: Make a button image->include it in your project->set the image as the "image" of the button.
-2: Make a button background image->include it in your project->set the image as the "background" of the button->set the "Title" of the button to anything you want.
Add the image in your project.
In IB set the button type to custom.
Set the image in Image or Background box just below the Title box.
That's all.
I actually had to drag and drop the images folder into the Project Navigator and chose that the folder is a reference and only then, I could see the images in the Media Library.
From there the only thing you need to do is drag the picture where you want or change for the image name in the Attribute inspector.