UIBarButtonItem with custom image and no border

前端 未结 9 698
旧巷少年郎
旧巷少年郎 2020-12-12 12:18

I want to create a UIBarButtonItem with a custom image, but I don\'t want the border that iPhone adds, as my Image has a special border.

It\'s the same as the back b

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 13:09

    You can add a method to UIBarButtonItem without subclassing it using custom category:

    @interface UIBarButtonItem(MyCategory)
    
    + (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action;
    
    @end
    
    @implementation UIBarButtonItem(MyCategory)
    
    + (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action{
     // Move your item creation code here
    }
    @end
    

    So anywhere in your code you can create bar item calling this method (provided that you include a header with its declaration).

    P.S. You do not need to use 'v' UIView as you can create UIBarButtonItem with a button as custom view directly.
    P.P.S. You also need [forward release] in your code.

提交回复
热议问题