• UIPopoverController 的使用


    #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.

    }

     

     

  • 相关阅读:
    Tomcat建立多个应用(Web Server),多个主机,多个站点的方法
    Spring 注解bean默认名称规则
    spring+springMVC,声明式事务失效,原因以及解决办法
    Spring事务失效的原因
    MySQL 对于千万级的大表要怎么优化?
    前端开发利器: Bootstrap + AngularJS
    scrapy爬取段子
    scrapy安装
    xpath和CSS选择器
    pycharm远程登录mysql
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4655824.html
Copyright © 2020-2023  润新知