簡體   English   中英

UINavigatiobar右barbutton項目圖像不可見

[英]UINavigatiobar right barbutton item image not visible

我正在為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. 要在運行時調試視圖,可以在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM