zoukankan      html  css  js  c++  java
  • 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.

    }

     

     

  • 相关阅读:
    2011年03月28日
    如何响应UIScrollView的touchesBegan和touchesEnd消息
    使用Git在Mac和Windows系统之间进行同步数据
    ActionScript 3.0 编程 中文版PDF下载地址
    WIN7 英文 语言包(KB972813)/多国语言包下载(转)
    如何根据内容和字体调整UILabel的大小
    xcode 快捷键(转)
    VMware, Win7, Mac系统之间使用Git版本控制器的解决方案
    iOS 开发教程资源列表(转载)
    取消UITableViewCell高亮颜色
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4655824.html
Copyright © 2011-2022 走看看