How to create a custom icon for a UIBarButton? - ios

Swift
I want to create a custom icon downloaded from the internet for a UIBarButton. Do I have to do this programmatically or can I some how find a setting via storyboard? If I choose "custom" it doesn't lead to further choosing of custom icons or anything so I'm not really sure what to do here.
I see there is a "Bar Item: Image" section. Is this what I will use?
http://prntscr.com/5x7gn0
Thanks!

Yes, the image (at the end of that link you posted) is where you would select your image. You need to put it into your project first though.
So steps to do:
Drag the image (hopefully it's in PNG format?) into the sidebar in the left and tick the checkbox titled "Copy items if needed" and click finish. Now you should see the image in your project.
Go to that place in interface builder that you have in the link (here: http://prntscr.com/5x7gn0) and select the image you added from the drop down list.
There is another way you can do this; programmatically, but it's slightly trickier. You still do step 1 but then instead of step 2, you can create an outlet to the Bar Button item and set its image like this:
barButtonItem.image = UIImage(named: "imageName.PNG")
If you need any clarification of what I've said, feel free to ask.
Loic

Related

Setting button image also ends up adding the word "button" to image; how to fix

So I made some assets in sketch and have successfully imported them into Xcode. When I attempt to give a button the image of one of these assets, Xcode does just that, but it also ends up adding the word "button" next to my image (seen in picture). I have a feeling my settings in the inspector could be the culprit, however playing around with them has yielded no victory.
Would you be able to recommend any solution?
Thanks]1
Remove the Button title "Button" from the inspector.
If you want button title and background image then assign your image into Background field which is below Image field and if you don't want button title then assign that image in Image field and remove title Button.
See the picture. By default it will take the title as Button. delete it. This will resolve your issue.

How to successfully add an image in Storyboard in Xcode 6 in Swift?

I'm very new to Xcode (2 days) and so far I'm finding it fairly frustrating. I'm just trying to add an image to my app's ViewController via he Storyboard, but it does not appear on the simulator. Could someone assist me?
if you are trying an example project of XCode, you may find a "Images.xcassets" folder in project. Drag your image into this folder.
then go to storyboard, focus on your "Image View".
in the attributes list, "Image" field, you can choose the image in it's drop-down menu.
the try running in simulator
good luck!
Here are some details on xcode 10.
Edit the story board, create an image view. Wayne stated, add the image you want in the Images.xcassets.
Click on your image view:
Do View -> Inspectors -> Show Attribute Inspector
Select the image:
After loading your image in the " Assets.xcassets" folder you will need to find the "Attributes inspector" under your right side inspectors tab. Focus or click on your "Image view" that you have to place as a holder on the storyboard. On the right tab under the attributes inspector (looks like a down arrow next to the ruler) you can select your image from the drop-down selection. You may also want to change Content mode to Aspect Fit while you are there.

Handling Button states

Hello I have another problem/question. I have a custom control with a button on it:
I want to delete an image from it, so I removed the reference from Attributes inspector -> Image, so now my button in designer looks like this:
But when I launch it on simulator, when I press the button (just push it, not making a click ) the image shows up! Where does it come from? Are there any button states styles in project files, where this could be written?
Because button has two references - 1 outlet and 1 action and none of those are used to add image to the button! I just don't understand where from the image gets in...
You should remove the image for both normal and selected states of the button from the attribute inspector(check stateConfig attribute).

Highlighted property is only for display within Interface Builder

How do I solve such warning? What does it mean in most of the cases?
When I click on it, there is nothing highlighted on my Interface Builder (it just zooms in on some area between 2 view controllers).
You have a UIImageView with Highlighted set to true in Xcode. Xcode tells you that the value is for WYSIWYG but won't work at runtime.
After looking at warning message details I got to know, but still there was no way, I could find particular Image is having highlighted="YES"
Perfect Trick suggested by #Keller in Accepted answer's comment.
Just right click your Storyboard --> Open As --> Source Code.
search for
highlighted="YES
Just set YES to NO.
or event if you look carefully code around searched string, you can get in which ViewController's Scene particular ImageView.
Thanks to #Keller
Right click on your Storyboard -> Open as -> Source Code.
Search for highlighted = "YES".
Check the name of the image.
Find the image on the Storyboard.
Click the image, go to Show the Attributes inspector.
Uncheck the Highlighted option
Highlighted image

Adding images to buttons in interface builder

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.

Resources