UIPopoverPresentationController无法设置箭头颜色

时间:2016-04-17 06:54:22

标签: ios objective-c iphone uipopovercontroller

我试图在iPhone上使用UIPopoverPresentationController类呈现popover。 我需要在popover中提供导航控制器。所以我做了以下几点:

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    viewController.preferredContentSize = size;
    navigationController.modalPresentationStyle = UIModalPresentationPopover;
    self.currentPopoverController = navigationController.popoverPresentationController;
    self.currentPopoverController.backgroundColor = [UIColor commonApplicationBgColor];//My common app blue color
    self.view.alpha = 0.7;
    [self presentViewController:navigationController animated:YES completion:nil];

它正常工作,但箭头颜色与弹出式导航栏背景颜色不同。我检查他们使用相同的[UIColor commonApplicationBgColor],但它看起来像箭头颜色更暗。尝试了self.currentPopoverController.backgroundColor的设置alpha,但它仍然有错误的颜色。 请检查图片: enter image description here

1 个答案:

答案 0 :(得分:-1)

如果您不想要箭头,那么您可以将0传递给permittedarrowdirection,例如

[popoverController presentPopoverFromRect:YOUR_RECT
                                inView:self.view 
              permittedArrowDirections:0
                              animated:YES];

更新:

你可以设置,

 popover = [[UIPopoverController alloc] initWithContentViewController:contentViewController];
 popover.backgroundColor = contentViewController.view.backgroundColor; 

将bacground颜色设置为popovercontroller。

更新2:

myPopoverViewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:myPopoverViewController animated: YES completion: nil];

// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
     [myPopoverViewController popoverPresentationController];
 presentationController.permittedArrowDirections =
     UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight;
  presentationController.sourceView = myView;
 presentationController.sourceRect = sourceRect;

presentationController.backgroundColor = [UIColor grayColor]; //set your expacted color here.

希望这会有所帮助