How to add icon next to tile in UINavigationController title?

newbie

I'm trying to add a drop down arrow or an icon next to the title of navigation bar (shown in screenshot below) but haven't found a good solution, I thought it would be fairly straight forward but I just can't get a good solution going.

One approach I tried is to replace the title with a UIButton by setting the view controller's navigationItem.titleView but the problem with this approach is since my title can vary in length I can't the button frame size calculated the CGRect is reported as 0,0. If I try to update the button's frame in viewWillDisplay() method then the button frame change is zoomed in animated in place and it's visible to the user and quite a jarring effect.

Are there any other possible solutions, I feel like I'm just approaching this all wrong, it shouldn't be this hard.

Nav bar with arrow

Leo

You can set a label with attributedstring,it will auto resize

Short title

enter image description here

Long title

enter image description here

For example

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,100, 40)];
label.textAlignment = NSTextAlignmentCenter;
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
NSTextAttachment * attach = [[NSTextAttachment alloc] init];
attach.image = [UIImage imageNamed:@"memoAccess"];
attach.bounds = CGRectMake(0, 0, 20, 20);
NSAttributedString * imageStr = [NSAttributedString attributedStringWithAttachment:attach];
NSMutableAttributedString * mutableAttriStr = [[NSMutableAttributedString alloc] initWithString:@"Title"];
[mutableAttriStr appendAttributedString:imageStr];
label.attributedText = mutableAttriStr;
self.navigationItem.titleView = label;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to center a title while ignoring the icon next to it?

From Dev

How to add title, snippet and icon to ClusterItem?

From Dev

How to add page title and icon in android FragmentPagerAdapter

From Dev

Add icon with title in CollapsingToolbarLayout

From Dev

How to read the font of the title in UINavigationController?

From Dev

Add text next to icon

From Dev

How can I make an icon appear next to my title in the <title> tag?

From Dev

How can I make an icon appear next to my title in the <title> tag?

From Dev

how to add icon on title in jquery dialog-extend

From Dev

How to add "menu" indicator next to Action Bar's app icon?

From Dev

How to add a font awesome icon next to the post date in wordpress

From Dev

How to localized app tile title in app list?

From Dev

Cordova - How to get a tile title on Windows mobile

From Dev

how to show icon with title in dialog

From Dev

Adding icon next to fieldset legend title and displaying tooltip

From Dev

Displaying post format icon next to the title in recent posts

From Dev

How to add an UINavigationController to an existing UIViewController programmatically

From Dev

How to add another UIViewController to an existing UINavigationController

From Dev

How to add a NavigationItem to a programmatically created UINavigationController

From Dev

How to add an UINavigationController to an existing UIViewController programmatically

From Dev

How to add Icon to JPanel

From Dev

How to show busy icon when leaflet api load tile images

From Dev

How to add geom_tile outside of axis?

From Dev

How to add geom_tile outside of axis?

From Dev

How to add a shutdown tile to the start screen?

From Dev

How to add a "metro" looking tile for a desktop application?

From Dev

How to make a Tile class and add it to a JFrame?

From Dev

How to change the title bar icon using winapi

From Dev

How to show glyphicon icon in kendo window title?

Related Related

  1. 1

    How to center a title while ignoring the icon next to it?

  2. 2

    How to add title, snippet and icon to ClusterItem?

  3. 3

    How to add page title and icon in android FragmentPagerAdapter

  4. 4

    Add icon with title in CollapsingToolbarLayout

  5. 5

    How to read the font of the title in UINavigationController?

  6. 6

    Add text next to icon

  7. 7

    How can I make an icon appear next to my title in the <title> tag?

  8. 8

    How can I make an icon appear next to my title in the <title> tag?

  9. 9

    how to add icon on title in jquery dialog-extend

  10. 10

    How to add "menu" indicator next to Action Bar's app icon?

  11. 11

    How to add a font awesome icon next to the post date in wordpress

  12. 12

    How to localized app tile title in app list?

  13. 13

    Cordova - How to get a tile title on Windows mobile

  14. 14

    how to show icon with title in dialog

  15. 15

    Adding icon next to fieldset legend title and displaying tooltip

  16. 16

    Displaying post format icon next to the title in recent posts

  17. 17

    How to add an UINavigationController to an existing UIViewController programmatically

  18. 18

    How to add another UIViewController to an existing UINavigationController

  19. 19

    How to add a NavigationItem to a programmatically created UINavigationController

  20. 20

    How to add an UINavigationController to an existing UIViewController programmatically

  21. 21

    How to add Icon to JPanel

  22. 22

    How to show busy icon when leaflet api load tile images

  23. 23

    How to add geom_tile outside of axis?

  24. 24

    How to add geom_tile outside of axis?

  25. 25

    How to add a shutdown tile to the start screen?

  26. 26

    How to add a "metro" looking tile for a desktop application?

  27. 27

    How to make a Tile class and add it to a JFrame?

  28. 28

    How to change the title bar icon using winapi

  29. 29

    How to show glyphicon icon in kendo window title?

HotTag

Archive