1

我创建了一个UINavigationBar比苹果默认导航栏高一点的自定义。

我似乎找不到将UIBarButtonItem向下移动到两条虚线之间直接居中的方法。

是否有捷径可寻?我试过创建一个自定义按钮,但没有成功。理想情况下,我只想将默认的后退按钮向下移动几个像素。

在此处输入图像描述

用于创建UINavigationBar自定义标题图像的代码和UIBarButtonItem

    //Create image for navigation background
UIImage *NavigationPortraitBackground = [[UIImage imageNamed:@"navbackground.png"]
                                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage: NavigationPortraitBackground
                                   forBarMetrics:UIBarMetricsDefault];

//Centered title image
UIImageView *headerImage = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"hometitle.png"]];
    [headerImage setFrame: CGRectMake(0, 0, 180, 49)];
self.navigationItem.titleView = headerImage;

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] init];
[backBarButtonItem setTintColor: [UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]];
[backBarButtonItem setStyle: UIBarButtonItemStylePlain];
    self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];

提前致谢,

4

2 回答 2

3

使用自定义视图创建 UIBarButtonItem。这个自定义视图将是一个 UIView,其中实际的 UIButton(作为子视图)从顶部放置 x 个像素(x=您想要将其向下移动的像素数)。

于 2012-06-13T10:22:45.133 回答
-1

对不起

UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeCustom];  
 [myButton1 setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];   myButton1.showsTouchWhenHighlighted = YES;  
 myButton1.frame = CGRectMake(0.0, 3.0, 50,30);  
  [myButton1 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:myButton1];    
 self.navigationItem.leftBarButtonItem = leftButton;
于 2012-06-13T10:51:30.230 回答