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. 《ServerSuperIO Designer IDE使用教程》- 7.增加机器学习算法,通讯采集数据与算法相结合。发布:4.2.5 版本

    v4.2.5更新内容:1.修复服务实例设置ClearSocketSession参数时,可能出现资源无法释放而造成异常的情况.2.修复关闭宿主程序后进程仍然无法退出的问题.2.增加机器学习框架.3.优化 ...

  2. Go-for循环

    一.第一种情况(死循环) package main import "fmt" func main() { for{ fmt.Println("fuck") } ...

  3. Spring MVC的注解二

    概述 Spring从2.5版本开始引入注解,虽然版本不断变化,但是注解的特性一直被延续下来并不断进行扩展,这里就来记录一下Spring MVC中常用的注解,本文承接前文继续记录@PathVariabl ...

  4. PHP SimpleXMLElement::__toString SimpleXML 函数

    定义和用法 SimpleXMLElement::__toString - 返回字符串内容 版本支持 PHP4 PHP5 PHP7 不支持 支持 支持 语法 SimpleXMLElement::__to ...

  5. iOS随记

    ios 10 访问设置问题 从ios8之api支持访问设置通过访问UIApplicationOpenSettingsURLString来跳转设置 NSURL*url=[NSURL URLWithStr ...

  6. idea找不到terminal

    起因是这样的,我要用命令行,懒,不想开cmd但是该死的我的idea找不见terminal,好奇怪哦,于是我查了一下,原来设置它蒙蔽了我的眼. 下面给出流程: 一般像我这样比较好学的好孩子不懂就比较喜欢 ...

  7. python3.7安装, 解决pip is configured with locations that require TLS/SSL问题

    python3.7安装, 解决pip is configured with locations that require TLS/SSL问题1.安装相关依赖 yum install gcc libff ...

  8. MongoDB 不在开源了,使用 Homebrew 安装只能玩社区版了

    使用了大半年的 mongodb ,最近在公司的新项目中应用,在 mac 上安装 mongodb 时发现始终安装不了,一直在报下面这样的错误: brew install mongodb 升级 brew  ...

  9. node.js守护进程问题的解决

    最近自己写了一个node.js来读取redis数据,编写完成后按理来说加& 应该是有效的 nohup node redis.js & 但是每次关闭终端后这个进程就自动停止了,百度了下 ...

  10. 【西北师大-2108Java】第六次作业成绩汇总

    [西北师大-2108Java]第六次作业成绩汇总 作业题目 面向对象程序设计(JAVA) 第8周学习指导及要求 实验目的与要求 (1)掌握接口定义方法: (2)掌握实现接口类的定义要求: (3)掌握实 ...