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