How to display image and text in NSPopupButton's items - macos

I am working on an application and I am using NSPopupButton to have drop-down list.
I would like to know how could I display image + text in every item when I expand the list. I have seen that in the interface there is addItemWithTitle: but it takes NSString.
How could I achieve that?
Thanks

[popUpButton addItemWithTitle:#"item title here"];
[[popUpButton lastItem] setImage:[NSImage imageNamed:#"noname01"]];
You don't need to consider a custom view.

The items in an NSPopUpButton are NSMenuItems which allow you to set an image for them in addition to text.

Add the image and set the position on each menu item, like shown in the image below:

Related

ListView with toolbar menu like function

I would like to ask a question regarding if it would be possible to make a toolbar like the droid tool bar's secondary items bar inside a listview? Picture shown below:
This is very easy to do. You can put this panel with menu in the header of the listview if you dont mind it to scroll up with the data. Or you can create a grid with 2 rows, put menu panel in row 0, put listview in row 1.
Your question is not very clear. If I understand it correctly, you would like to number the items of a list view.
This can be done by overriding the functionality of the getView() function.
Check for an example here

image and text width in a UIButton

All,
I have an button like this :
i want to give a little more space between the icon and the text.. Is this possible in Interface Builder ?
Yes, select your button and in the attributes inspector you can set the image insets.
Sure, in IB you can configure options Edge Insets for UIButton.
It's well explained in this post, in the The Lazy Coder reply.

How to make UIPickerView that appears if i click on the UITextField?

How can i make a UIPickerView that appears when i select a TextField, and the input of this comes into TextField if i select a value of UIPickerView?
How to do this? Have you an example of this?
Create the UIPickerView and set it as the inputView of your text field. It will then be animated on screen for you when you start editing the text field. The picker view delegate methods can be used to update the text field's value.
You will also want to create a toolbar with a done button and set this as the inputAccessoryView - this will allow you to dismiss the picker when you have selected your value. Again, this will appear automatically above the picker view when the text field begins editing.
Please take a look at this example http://www.techotopia.com/index.php/An_iOS_4_iPhone_UIPickerView_Example
You can initially hide the picker by
picker.hidden=YES; in your viewdidload method and for showing it when touch on the textfield you can write picker.hidden=NO; inside uitextfielddidstartediting method. Thanks.

How do I add a title to a button which has a custom image?

I made a button with IB then added custom images for different states but my title never appears on my button. How can I fix it? In fact, I just want to add my text over the image.
You can set your button images as background images in interface builder, then the text will appear.
It will not appear because the image is on top of it, you can either:
1) Use backgroundImage instead of image
2) Create an image with the text already on it
3) Create a button with a transparent part where the text will go
4) Have your image and your text in the button, but say one on the left and one on the right, you can do this with this properties: titleEdgeInsets and imageEdgeInsets
5) Add the label and uiimage as subviews of uilabel.
start with a regular button type in the title and switch it to a custom button, if you want the background to be changed import and use the command yourButton.backgroundColor = [UIColor grayColor];
Try to change the Button type to "Custom" and then add the image as Background Image. Now u will be able to see the desired look.

Setting TabBarItem title

I'm using the TabBar for the very first time. I see that I can easily add tabbar items to it. And I see that I can set a icon to it (choosing the identifier). I do so, but when I try to change the title, the identifier -and the icon- go away...
why? Can't I keep predefined icons with custom title text?
Thanks!
The title replaces any image, you can't have image and title on a UIBarButtonItem

Resources