iphone - 无法使用自定义 View 触发条形按钮项目?

标签 iphone objective-c ios cocoa-touch ios5

在我的 iPhone 应用程序中,

我有一个要设置的导航栏图像我已经这样设置了....

   if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){

        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBarReady.png"] forBarMetrics:UIBarMetricsDefault];
    }

    UIBarButtonItem *bbiLeft=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btnBack.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnBackPressed:)]; 
    [bbiLeft setTintColor:[UIColor clearColor]];
    [bbiLeft setBackgroundVerticalPositionAdjustment:7.0f forBarMetrics:UIBarMetricsDefault];
    self.navigationItem.leftBarButtonItem=bbiLeft;

看起来是这样的……

enter image description here

我想将它的颜色设置为导航栏的背景

如何? 谢谢..

最佳答案

得到答案...

/* Back Button setted*/    
    UIButton *btnBack=[UIButton buttonWithType:UIButtonTypeCustom];
    [btnBack addTarget:self action:@selector(btnBackPressed:) forControlEvents:UIControlEventTouchUpInside];
    [btnBack setImage:[UIImage imageNamed:@"btnBack.png"] forState:UIControlStateNormal];
    [btnBack setFrame:CGRectMake(0, 0, 51,16)];
    UIView *backModifiedView=[[UIView alloc] initWithFrame:btnBack.frame];
    [btnBack setFrame:CGRectMake(btnBack.frame.origin.x, btnBack.frame.origin.y+7, btnBack.frame.size.width, btnBack.frame.size.height)];
    [backModifiedView addSubview:btnBack];
    UIBarButtonItem *bbiLeft=[[UIBarButtonItem alloc] initWithCustomView:backModifiedView];
      self.navigationItem.leftBarButtonItem=bbiLeft;



/* Arpit */
//set Navgation Bar.   
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){

        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBarReady.png"] forBarMetrics:UIBarMetricsDefault];
    }

关于iphone - 无法使用自定义 View 触发条形按钮项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8987270/

相关文章:

iPhone SDK : How to remove the horizontal markers from Core-Plot?

objective-c - 将可变数量的参数传递给选择器

ios - View Controller 和类之间有什么区别

ios - 删除单元格后,swift tableview 不会重新加载

ios - 使用组合字符串从 url 快速加载图像

ios - 如何在 iOS 中打开文件?

iphone - 如何重用 UIImage

CSS :active override similar to iPhone TouchUpInside

iphone - UIActionSheet 和 Twitter 用户名选择

ios - 具有核心数据的具有挑战性的在线数据库持久性?