1

5 ピクセル下に微調整したいカスタム バー ボタン項目があります。次のコードでそれを行うにはどうすればよいですか。「y」ポイントを設定しようとしましたが、構文エラーが発生し続けます。

     [self.navigationController setNavigationBarHidden:NO animated:YES];

     UIImage *image = [UIImage imageNamed:@"arrow_back.png"];
     UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

     [self.navigationController.navigationBar addSubview:imageView];

    [imageView release];

     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
     [button setImage:buttonImage forState:UIControlStateNormal];

     //set the frame of the button to the size of the image (see note below)
     button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

     //create a UIBarButtonItem with the button as a custom view
     UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
     self.navigationItem.leftBarButtonItem = customBarItem;

    [customBarItem release];
}

助けてくれてありがとう

4

1 に答える 1

3

UIBarButtonアイテムはUIViewから継承しないため、直接調整できる「フレーム」プロパティがないため、別のメソッドを使用する必要があります。

試す:

    [self.navigationItem.leftBarButtonItem setBackgroundVerticalPositionAdjustment:5 forBarMetrics:UIBarMetricsDefault];
于 2012-05-17T11:00:27.407 に答える