UIViewController *contentViewController = [[UIViewController alloc] init];
contentViewController.view.backgroundColor = [UIColor yellowColor]; UIPopoverController *popController = [[UIPopoverController alloc] initWithContentViewController:contentViewController];
// popController.popoverBackgroundViewClass = [PopoverBackgroundView class];
popController.popoverContentSize = CGSizeMake(300.0f, );
self.popController = popController; UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[contentViewController.view addSubview:button]; [self.popController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];

也可以自定义背景

#import <UIKit/UIKit.h>
@interface PopoverBackgroundView : UIPopoverBackgroundView
@end
#import "PopoverBackgroundView.h"
#define kArrowBase 30.0f
#define kArrowHeight 20.0f
#define kBorderInset 0.0f @interface PopoverBackgroundView()
@property (nonatomic, strong) UIImageView *arrowImageView;
- (UIImage *)drawArrowImage:(CGSize)size;
@end @implementation PopoverBackgroundView @synthesize arrowDirection = _arrowDirection;
@synthesize arrowOffset = _arrowOffset; #pragma mark - Graphics Methods
- (UIImage *)drawArrowImage:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, NO, );
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor clearColor] setFill];
CGContextFillRect(ctx, CGRectMake(0.0f, 0.0f, size.width, size.height)); CGMutablePathRef arrowPath = CGPathCreateMutable();
CGPathMoveToPoint(arrowPath, NULL, (size.width/2.0f), 0.0f); //Top Center
CGPathAddLineToPoint(arrowPath, NULL, size.width, size.height); //Bottom Right
CGPathAddLineToPoint(arrowPath, NULL, 0.0f, size.height); //Bottom Right
CGPathCloseSubpath(arrowPath);
CGContextAddPath(ctx, arrowPath);
CGPathRelease(arrowPath); UIColor *fillColor = [UIColor yellowColor];
CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
CGContextDrawPath(ctx, kCGPathFill); UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image; } #pragma mark - UIPopoverBackgroundView Overrides
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor]; //TODO: update with border image view
UIImageView *arrowImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
self.arrowImageView = arrowImageView;
[self addSubview:self.arrowImageView]; }
return self;
} + (CGFloat)arrowBase
{
return kArrowBase;
} + (CGFloat)arrowHeight
{
return kArrowHeight;
} + (UIEdgeInsets)contentViewInsets
{
return UIEdgeInsetsMake(kBorderInset, kBorderInset, kBorderInset, kBorderInset);
} + (BOOL)wantsDefaultContentAppearance
{
return NO;
} - (void)layoutSubviews
{
[super layoutSubviews]; //TODO: test for arrow UIPopoverArrowDirection
CGSize arrowSize = CGSizeMake([[self class] arrowBase], [[self class] arrowHeight]);
self.arrowImageView.image = [self drawArrowImage:arrowSize]; self.arrowImageView.frame = CGRectMake(((self.bounds.size.width - arrowSize.width)- kBorderInset), 0.0f, arrowSize.width, arrowSize.height); }

iOS UIPopoverView的使用的更多相关文章

  1. iOS 7 隐藏特性

    当 iOS7 刚发布的时候,全世界的苹果开发人员都立马尝试着去编译他们的app,接着再花上数月的时间来修复任何出现的故障,甚至重做app.这样的结果,使得人们根本无暇去探究 iOS7 所带来的新东西. ...

  2. 对于iOS 7 隐藏特性和解决之道

    当 iOS7 刚发布的时候,全世界的苹果开发人员都立马尝试着去编译他们的app,接着再花上数月的时间来修复任何出现的故障,甚至重做app.这样的结果,使得人们根本无暇去探究 iOS7 所带来的新东西. ...

  3. iOS可视化动态绘制连通图

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  4. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  5. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  6. iOS总结_UI层自我复习总结

    UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...

  7. iOS代码规范(OC和Swift)

    下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...

  8. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  9. 告别被拒,如何提升iOS审核通过率(上篇)

    iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...

随机推荐

  1. zookeeper的java问题

    执行bash ./bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /data/zookeeper-3.4.9/b ...

  2. 快速掌握MIPI开发攻略,对接百度人工智能计算卡EdgeBoard

    MIPI(移动行业处理器接口)是Mobile Industry Processor Interface的缩写,是MIPI联盟发起的为移动应⽤处理器制定的开放标准.MIPI采⽤高速串行接口传输数据,满⾜ ...

  3. QT防止程序多次启动

    Question:最近在linux下作的一个项目,设置了crontab自启动,但是经常出现启动多个进程的原因,针对这种情况,我做了如下处理: QLockFile *lockFile = new QLo ...

  4. 42-volume 生命周期管理

    Data Volume 中存放的是重要的应用数据,如何管理 volume 对应用至关重要.前面我们主要关注的是 volume 的创建.共享和使用,本节将讨论如何备份.恢复.迁移和销毁 volume. ...

  5. fuse3 编译相关简要记录 与 fuse3 系统调优;

    下面是在使用fuse3 编译bbfs 过程中一些参数,用于备忘: FUSE_CFLAGS="-I/usr/local/include/fuse3" FUSE_LIBS=" ...

  6. STL 中 map 的使用

    涉及:vector,pair 基本结构 map 从本质上来说是一颗二叉排序树,树上的节点类型为pair.pair类型中有两个重要的成员变量,其中 first 存储了 key ,second 存储了 v ...

  7. 冒泡排序和sort,sorted排序函数

    冒泡: # 轮数 元素个数 比较次数# 1 6 5# 2 5 4# 3 4 3# 4 3 2# 5 2 1 # 列表有n个元素,则应比较n-1轮,即循环次数n-1 a=[85,7,4,89,34,2] ...

  8. mysql中group by 使用

    问题描述 我现在需要查询表test,里面需要安装字段a 进行分组.分组之后还有按照b字段最大的.还要查询出字段c. 我先在使用的数据库是mysql8.0 解决 需注意: group by 分组的时候是 ...

  9. LeetCode解题笔记 - 4. Median of Two Sorted Arrays

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  10. rabbit mq 手动重试机制

    消息手动确认模式的几点说明 监听的方法内部必须使用channel进行消息确认,包括消费成功或消费失败 如果不手动确认,也不抛出异常,消息不会自动重新推送(包括其他消费者),因为对于rabbitmq来说 ...