码迷,mamicode.com
首页 > 其他好文 > 详细

UIPopoverController 的使用

时间:2015-07-18 00:16:43      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

#import "RYColorSelectController.h"

#import "RYMenuViewController.h"

#import "RYTitleViewController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    //设置菜单按钮

    

    UIBarButtonItem *leftItem=[[UIBarButtonItem alloc]initWithTitle:@"菜单" style:UIBarButtonItemStylePlain target:self action:@selector(menuClick:)];

    self.navigationItem.leftBarButtonItem=leftItem;

    

    

    

    UIButton *btn=[[UIButton alloc]init];

    [btn setTitle:@"主题" forState:UIControlStateNormal];

    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [btn sizeToFit];

    self.navigationItem.titleView=btn;

    [btn addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];

    

    

    

}

 

-(void)titleClick:(UIButton*)sender

{

    RYTitleViewController *title=[[RYTitleViewController alloc]init];

    

    title.view.backgroundColor=[[UIColor alloc]initWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1];

    

    UIPopoverController* pop=[[UIPopoverController alloc]initWithContentViewController:title];

//第一种添加方式

    [pop presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    

    

}

 

 

-(void)menuClick:(UIBarButtonItem*)sender

{

    RYMenuViewController *title=[[RYMenuViewController alloc]init];

    title.view.backgroundColor=[[UIColor alloc]initWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1];

    

    UIPopoverController* pop=[[UIPopoverController alloc]initWithContentViewController:title];

//第二种添加方式

//    //设置穿透哪些控件 pop出来的控制器覆盖在其他的控件上的时候,设置被覆盖的控件也可以被点击

//    selectColorPopover.passthroughViews = @[self.btnClick];

    [pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

 @end

 

 

#import <UIKit/UIKit.h>

@interface RYMenuViewController : UITableViewController

 

@end

#import "RYMenuViewController.h"

 

@interface RYMenuViewController ()<UITableViewDataSource,UITableViewDelegate>

 

@property(nonatomic,strong)NSArray *allData;

 

@end

 

 

 

 

 

@implementation RYMenuViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    self.tableView.dataSource=self;

    self.tableView.delegate=self;

    

    ///设置展示界面大小

    self.preferredContentSize = CGSizeMake(100, 200);

 

    

}

 

-(NSArray*)allData

{

    if (_allData==nil) {

        _allData=@[@"博客",@"好友",@"拖拉机",@"shangpin"];

    }

    return _allData;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return  self.allData.count;

}

 

 

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString*inderface=@"cell";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:inderface];

    if (!cell) {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:inderface];

    }

    cell.textLabel.text=self.allData[indexPath.row];

    return cell;  

}

 

 @end

#import <UIKit/UIKit.h>

 

@interface RYTitleViewController : UIViewController

 

@end

#import "RYTitleViewController.h"

 

@interface RYTitleViewController ()

 

@end

 

@implementation RYTitleViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    ///设置展示界面大小

    self.preferredContentSize = CGSizeMake(100, 100);

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

UIPopoverController 的使用

标签:

原文地址:http://www.cnblogs.com/tangranyang/p/4655824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!