【问题标题】:UIPopoverPresentationController can't setup arrow colorUIPopoverPresentationController 无法设置箭头颜色
【发布时间】:2016-04-18 00:54:29
【问题描述】:

我正在尝试在 iPhone 上使用 UIPopoverPresentationController 类呈现弹出框。 我需要在弹出框内显示导航控制器。所以我做了以下事情:

    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,但它仍然有错误的颜色。 请检查图像:

【问题讨论】:

  • 你是从rect展示它吗?
  • 是的,代码如下: self.currentPopoverController.delegate = self; self.currentPopoverController.sourceView = self.view; self.currentPopoverController.sourceRect = 框架;
  • 自 iOS 7 以来,Popover 效果不太好。Apple 在自己的应用程序中并没有大量使用它,这就是结果。

标签: ios objective-c iphone uipopovercontroller


【解决方案1】:

如果你不想要箭头,那么你可以将 0 传递给 permittedarrowdirection 喜欢,

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

更新:

你可以设置,

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

将免费颜色设置为 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.

希望这会有所帮助

【讨论】:

  • 不,我需要箭头。问题在于弹出箭头背景颜色。颜色比弹出框导航栏颜色深。请检查图片。
  • 是iPad版吗?请检查我的代码,我正在使用 popoverPresentationController
  • 对不起,首先我了解了 iPad 的 popoverController。我已经更新了我的答案检查它。
  • 谢谢,但是我的代码是一样的:self.currentPopoverController.backgroundColor = [UIColor commonApplicationBgColor];//我的普通应用程序蓝色,它不起作用,结果在上面的图像屏幕上.
猜你喜欢
  • 1970-01-01
  • 2019-04-19
  • 1970-01-01
  • 2015-03-07
  • 2013-08-04
  • 2015-01-14
  • 1970-01-01
  • 2017-02-22
  • 1970-01-01
相关资源
最近更新 更多