如何将图像添加到UIBarButtonItem?

Lea*_*nne 4 objective-c uibarbuttonitem navigationbar ios

我创建了一个自定义按钮并将其应用到UIbarbuttonitem.没有错误,但导航栏上没有显示任何内容:(这是我的代码 -

    //create a custom button
    UIImage *image = [UIImage imageNamed:@"TESTButton.png"];
    UIButton *myCustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
    myCustomButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );    
    [myCustomButton setImage:image forState:UIControlStateNormal];
    [myCustomButton addTarget:nil action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];


    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myCustomButton];
    self.navigationItem.leftBarButtonItem = button;
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

    [button release];
    [myCustomButton release];
    [image release];
    [navID release];
Run Code Online (Sandbox Code Playgroud)

谁可以修复我的代码?:)

Dex*_*erW 9

来自文档:

initWithImage:style:target:action:
Run Code Online (Sandbox Code Playgroud)

试试吧.