Change position of UIBarButtonItem in UINavigationBar

后端 未结 20 1565
一个人的身影
一个人的身影 2020-11-27 10:31

How can I change the position of a UIBarButtonItem in a UINavigationBar? I would like my button to be about 5px higher than its normal position.

20条回答
  •  时光说笑
    2020-11-27 10:57

    For those of you developing for iOS 5 who stumbled across this and were discouraged... Try something like this:

    float my_offset_plus_or_minus = 3.0f;
    
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithTitle:@"title" 
                                                              style:UIBarButtonItemStyleDone
                                                              target:someObject action:@selector(someMessage)];
    
    [item setBackgroundVerticalPositionAdjustment:my_offset_plus_or_minus forBarMetrics:UIBarMetricsDefault];
    

提交回复
热议问题