How to add a customized image button to UINavigationBar in iPhone sdk

前端 未结 1 1516
既然无缘
既然无缘 2021-02-11 05:08

I want to add customized arrow buttons to UINavigation Bar which comes at the top.

what I want to do is create a custom image button and place it over the bar. When I t

相关标签:
1条回答
  • 2021-02-11 05:50

    Try doing the following:

    UINavigationBar *bar = self.navigationController.navigationBar;
    bar.titleView = leftArrowButton;  // change title view
    bar.leftBarButtonItem = leftArrowButton; // if ref is UIBarButtonItem
    

    You should consider using a UIBarButtonItem rather than UIButton.

    You can also customize the bar buttons as well with images (using the initWithImage:style:target:action:):

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:myImage
                                 style:UIBarButtonItemStyleBordered
                                target:self action:@selector(buttonPressed:)];
    bar.leftBarButtonItem = item;
    [item release];
    

    You can also use any view you like (with some consideration for the size) using the initWithCustomView::

    UIBarButtonItem *item = [[UIBarButtonItem alloc]
                               initWithCustomView:leftArrowButton];
    bar.leftBarButtonItem = item;
    [item release];
    
    0 讨论(0)
提交回复
热议问题