我正在尝试使用UINavigationController
中的自定义后退按钮,但图片没有显示。
以下是代码:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
self.navigationController!.view.backgroundColor = UIColor.clearColor()
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "Back-50")
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "Back-50")
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
我不确定这段代码出了什么问题。
答案 0 :(得分:2)
如果您只想将图像显示为后退按钮,则将navigationBar的tintColor设置为清除颜色,然后将基于UIBarButtonItem的图像设置为控制器的navigationItem的backBarButtonItem。
let backButton = UIBarButtonItem(image: UIImage(named: "back"), style: .Plain, target: self, action: "back")
self.navigationController?.navigationBar.tintColor = UIColor.clearColor()
self.navigationItem.backBarButtonItem = backButton
这将使默认的后退按钮图像(<)不显示(实际上它显示但是它的颜色是清晰的,因此不可见)并且只显示背面图像。
答案 1 :(得分:2)
也许,你应该使用UIAppearance。
喜欢这个
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UINavigationBar appearance] setBackIndicatorImage: [UIImage imageNamed:@"icon-back"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage: [UIImage imageNamed:@"icon-back"]];
return YES;
}
在swift中
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "")
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "")
return true
}
答案 2 :(得分:1)
您必须在目标视图控制器中实现这些代码行,这意味着您将推送的控制器,因为您希望自定义返回项目按钮,该按钮仅在您将视图控制器推入导航控制器堆栈时处于活动状态。你的代码适合我。
答案 3 :(得分:1)
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "Back-50"), style: .Plain, target: self, action: "back")
func back(){
self.navigationController?.popViewControllerAnimated(true)
}
答案 4 :(得分:1)
试试这个
from django.views.decorators.csrf import csrf_exempt
愿这对你有所帮助
答案 5 :(得分:1)
试试这个为我工作。
var BackButton : UIBarButtonItem = UIBarButtonItem(image:
UIImage(named: "Back-50"), style: .Plain, target: self, action: "back")
self.navigationItem.leftBarButtonItem = BackButton
func back()
{
// your backcontroller code here....
}