gpt4 book ai didi

ios - 导航栏右栏按钮项目图像不可见

转载 作者:行者123 更新时间:2023-11-29 12:13:59 26 4
gpt4 key购买 nike

我正在为 UINavigation 栏创建自定义右栏按钮项。这是我正在使用的代码,

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
UIButton *backPageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backPageButton setFrame:CGRectMake(0, 0, 50, 30)];
[ backPageButton setImage:[UIImage imageNamed:@"left_arrow.png"] forState:UIControlStateNormal];
backPageButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[backPageButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
[backPageButton setUserInteractionEnabled:YES];
[container addSubview:backPageButton];
UIButton *forwardPageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[forwardPageButton setFrame:CGRectMake(30, 0, 50, 30)];
[ forwardPageButton setImage:[UIImage imageNamed:@"right_arrow.png"] forState:UIControlStateNormal];
[forwardPageButton addTarget:self action:@selector(forwardButtonAction) forControlEvents:UIControlEventTouchUpInside];
forwardPageButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[forwardPageButton setUserInteractionEnabled:YES];
[container addSubview:forwardPageButton];

UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];

// set the nav bar's right button item
self.navigationItem.rightBarButtonItem = item;

由于某些原因,按钮图像不可见。我为每个按钮添加了背景颜色,可以看到按钮实际上已添加到导航栏,而且点击事件也正常工作。但是按钮图像不可见。

如何解决?

谢谢

最佳答案

  1. 当然,您已经仔细检查过图像是否属于您的目标?
  2. 要在运行时调试您的 View ,您可以在 Xcode 中使用小但非常有用的按钮

http://i.stack.imgur.com/QFdDL.png

更多相关信息:https://developer.apple.com/library/ios/recipes/xcode_help-debugger/using_view_debugger/using_view_debugger.html

关于ios - 导航栏右栏按钮项目图像不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32447153/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com