0

我有一个从相机胶卷中提取的 UIImagePickerController。

在导航栏中,有一个默认的 UIBarButtonItem 取消选择照片,但它与我的应用程序完全不匹配!

如何更改它的外观甚至隐藏它,然后将我自己的按钮放在导航栏中的位置?

这很容易通过 Back 按钮完成,如下所示:

// Change the appearance of back button
UIImage *backButtonImage = [[UIImage imageNamed:@"back_button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 10, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

UIBarButtonItem 似乎没有 setCancelButtonBackgroundImage 方法。

4

1 回答 1

1

这个怎么样:

UIImage * cancelButtonImage = [UIImage imageNamed:@"cancel_button.png"];
UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton setFrame:(CGRect){CGPointZero, hamburgerImage.size}];
[cancelButton setImage:cancelButtonImage forState:UIControlStateNormal];
[cancelButton addTarget:self
                 action:@selector(cancel:)
       forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * cancelButtonItem = [[UIBarButtonItem alloc] initWithCustomView:cancelButton];
[self.navigationItem setLeftBarButtonItem:cancelButtonItem];
于 2013-09-06T02:02:02.493 回答