代码之家  ›  专栏  ›  技术社区  ›  Pugalmuni Tom Tharakan

在iPhone OS 4.0的导航栏中,返回按钮不可见

  •  1
  • Pugalmuni Tom Tharakan  · 技术社区  · 15 年前

    在我的应用程序(基于视图)中,后退按钮在导航栏中不可见。如果我点击那个按钮,动作就正常了。我觉得很奇怪。后退按钮在iPhoneOS3.0和其他操作系统(OS4.0除外)中可见并正常工作。我目前正在使用iPhone操作系统4.0。

    这是我的密码:

    UIButton *btn=[[UIButton alloc] init];
    
    [btn setImage:[UIImage imageNamed:@"Back.png"] forState:UIControlStateNormal];
    
    [btn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, 70, 0, 20)];
    UIBarButtonItem *b=[[UIBarButtonItem alloc] initWithCustomView:btn];    
    self.navigationItem.leftBarButtonItem=b;
    [b release];
    [btn release]; 
    

    注意:它不仅仅适用于iPhoneOS4.0。那么我该如何做到这一点呢?

    2 回复  |  直到 12 年前
        1
  •  1
  •   Sivanathan    15 年前

    只需在任何地方替换此代码,即可在OS4.0中正常工作。

    UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];
    
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];
    
    [myView addSubview:btn];
    
    UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,50,30)];
    
    [myImage setImage:[UIImage imageNamed:@"Back.png"]];
    
    [myView addSubview:myImage];
    
    [btn addTarget:self action:@selector(lOut) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *b1 = [[UIBarButtonItem alloc] initWithCustomView:myView];
    
    self.navigationItem.leftBarButtonItem = b1;
    
    [btn release];
    
    [b1 release];
    
    [myView release];
    
    [myImage release];
    

    我希望它能帮助你们。

        2
  •  0
  •   Baryon Lee    14 年前
    UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 40)];
    [btn setImage:[UIImage imageNamed:@"info44.png"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"info44_glowing.png"] forState:UIControlStateHighlighted];   
    [btn addTarget:[AppDelegate sharedAppDelegate]  action:@selector(settingAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *settingButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem = settingButton;
    [btn release];
    [settingButton release];