Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEPopover as iOS Framework #39

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Xcode
build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
.DS_Store
1 change: 0 additions & 1 deletion Classes/Popover/UIBarButtonItem+WEPopover.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
*/

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface UIBarButtonItem(WEPopover)
Expand Down
6 changes: 6 additions & 0 deletions Classes/Popover/WEPopover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
#import <WEPopover/WETouchableView.h>
#import <WEPopover/WEPopoverContainerView.h>
#import <WEPopover/WEPopoverController.h>
#import <WEPopover/WEPopoverParentView.h>
#import <WEPopover/UIBarButtonItem+WEPopover.h>
24 changes: 18 additions & 6 deletions Classes/Popover/WEPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ - (WEPopoverContainerViewProperties *)defaultContainerViewProperties {
WEPopoverContainerViewProperties *ret = [[WEPopoverContainerViewProperties new] autorelease];

CGSize imageSize = CGSizeMake(30.0f, 30.0f);
NSString *bgImageName = @"popoverBgSimple.png";
CGFloat bgMargin = 6.0;
CGFloat contentMargin = 2.0;

Expand All @@ -359,17 +358,30 @@ - (WEPopoverContainerViewProperties *)defaultContainerViewProperties {
ret.bottomBgMargin = bgMargin;
ret.leftBgCapSize = imageSize.width/2;
ret.topBgCapSize = imageSize.height/2;
ret.bgImageName = bgImageName;

ret.leftContentMargin = contentMargin;
ret.rightContentMargin = contentMargin;
ret.topContentMargin = contentMargin;
ret.bottomContentMargin = contentMargin;
ret.arrowMargin = 1.0;

ret.upArrowImageName = @"popoverArrowUpSimple.png";
ret.downArrowImageName = @"popoverArrowDownSimple.png";
ret.leftArrowImageName = @"popoverArrowLeftSimple.png";
ret.rightArrowImageName = @"popoverArrowRightSimple.png";
// Set the defaults images from framewor or from resources depending of the compilation type
ret.bgImageName = ([UIImage imageNamed:@"popoverBgSimple"] == nil)
? @"WEPopover.framework/popoverBgSimple"
: @"popoverBgSimple";
ret.upArrowImageName = ([UIImage imageNamed:@"popoverArrowUpSimple.png"] == nil)
? @"WEPopover.framework/popoverArrowUpSimple.png"
: @"popoverArrowUpSimple.png";
ret.downArrowImageName = ([UIImage imageNamed:@"popoverArrowDownSimple.png"] == nil)
? @"WEPopover.framework/popoverArrowDownSimple.png"
: @"popoverArrowDownSimple.png";
ret.leftArrowImageName = ([UIImage imageNamed:@"popoverArrowLeftSimple.png"] == nil)
? @"WEPopover.framework/popoverArrowLeftSimple.png"
: @"popoverArrowLeftSimple.png";
ret.rightArrowImageName = ([UIImage imageNamed:@"popoverArrowRightSimple.png"] == nil)
? @"WEPopover.framework/popoverArrowRightSimple.png"
: @"popoverArrowRightSimple.png";

return ret;
}

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
About WEPopover
===============

WEPopover is an attempt to create a generalized version of the UIPopoverController which is unfortunately only available for the iPad. WEPopover should work on any device with iOS >= 3.2. If you want to use it with iOS < 3.2 you need to implement the @property(nonatomic, readwrite) CGSize contentSizeForViewInPopover for the content view controllers you want to present manually.

The project contains some sample code illustrating the usage of the classes, but the only classes you actually need if you want to use the library reside in the "Popover" group in the project tree.

Please have a look at the UIPopoverController documentation on details of the API.
Additions to the UIPopoverController API include:

- Support for custom background views: specify the WEPopoverContainerViewProperties for the view to use as background. The properties specify the images to use for the stretchable background and the arrows (four directions). It also specifies the margins and the cap sizes for resizing the background. A default image with corresponding arrows are supplied with the project.
- Support for limiting the area to display the popover: implement the protocol WEPopoverParentView for the view you supply to the presentPopover method and implement the - (CGRect)displayAreaForPopover.
- Support for repositioning an existing popover (by passing the need to dismiss it and present a new one). See the 'repositionPopoverFromRect' method in WEPopoverController.


Integrate WEPopover in your project
===================================

The easiest way to integrate WEPopover in your project is build it as a framework. This option have many advantages over make it as subproject, especially if your project uses ARC. To Integrate it follow this easy steps:

1 - Download the WEPopover source code from https://github.com/werner77/WEPopover/

2 - Select as active scheme "WEPopover Framework" for *iPhone/iPad simulator* and build it
![](https://raw.github.com/JoseExposito/WEPopover/WEPopover-as-Framework/screenshots/Integrate_WEPopover_1.png)

3 - Go to the WEPopover source code folder, a "build" folder was generated with the "WEPopover.framework" in

4 - In your project, go to your target and in "Build Phases" tab add the WEPopover.framework by pressing the "+" button, clicking in "Select others" and selecting the framework

![](https://raw.github.com/JoseExposito/WEPopover/WEPopover-as-Framework/screenshots/Integrate_WEPopover_2.png)
![](https://raw.github.com/JoseExposito/WEPopover/WEPopover-as-Framework/screenshots/Integrate_WEPopover_3.png)

5 - In the "Summary" tab, add the WEPopover.framework in the "Linked Frameworks and Libraries" section
![](https://raw.github.com/JoseExposito/WEPopover/WEPopover-as-Framework/screenshots/Integrate_WEPopover_4.png)
22 changes: 22 additions & 0 deletions WEPopover Framework Example/Classes/WEPopoverAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// WEPopoverAppDelegate.h
// WEPopover
//
// Created by Werner Altewischer on 06/11/10.
// Copyright 2010 Werner IT Consultancy. All rights reserved.
//

#import <UIKit/UIKit.h>

@class WEPopoverViewController;

@interface WEPopoverAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@end

89 changes: 89 additions & 0 deletions WEPopover Framework Example/Classes/WEPopoverAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// WEPopoverAppDelegate.m
// WEPopover
//
// Created by Werner Altewischer on 06/11/10.
// Copyright 2010 Werner IT Consultancy. All rights reserved.
//

#import "WEPopoverAppDelegate.h"
#import "WEPopoverViewController.h"

@implementation WEPopoverAppDelegate

@synthesize window;
@synthesize navController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSLog(@"%@", [UIImage imageNamed:@"WEPopover.framework/popoverArrowDownSimple"]);
// Override point for customization after application launch.

// Add the view controller's view to the window and display.
[window addSubview:navController.view];
[window makeKeyAndVisible];

return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}


- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}


- (void)dealloc {
[navController release];
[window release];
[super dealloc];
}


@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// WEPopoverContentViewController.h
// WEPopover
//
// Created by Werner Altewischer on 06/11/10.
// Copyright 2010 Werner IT Consultancy. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface WEPopoverContentViewController : UITableViewController {

}

@end
130 changes: 130 additions & 0 deletions WEPopover Framework Example/Classes/WEPopoverContentViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//
// WEPopoverContentViewController.m
// WEPopover
//
// Created by Werner Altewischer on 06/11/10.
// Copyright 2010 Werner IT Consultancy. All rights reserved.
//

#import "WEPopoverContentViewController.h"


@implementation WEPopoverContentViewController


#pragma mark -
#pragma mark Initialization

- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if ((self = [super initWithStyle:style])) {
self.contentSizeForViewInPopover = CGSizeMake(100, 1 * 44 - 1);
}
return self;
}

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
[super viewDidLoad];

self.tableView.rowHeight = 44.0;
self.view.backgroundColor = [UIColor clearColor];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 1;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...
cell.textLabel.text = [NSString stringWithFormat:@"Item %d", [indexPath row]];
cell.textLabel.textColor = [UIColor whiteColor];
return cell;
}


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.

}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}


@end

21 changes: 21 additions & 0 deletions WEPopover Framework Example/Classes/WEPopoverTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// WEPopoverTableViewController.h
// WEPopover
//
// Created by Werner Altewischer on 1/4/11.
// Copyright 2011 Werner IT Consultancy. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface WEPopoverTableViewController : UITableViewController<WEPopoverControllerDelegate, UIPopoverControllerDelegate> {
WEPopoverController *popoverController;
NSInteger currentPopoverCellIndex;
Class popoverClass;
}

@property (nonatomic, retain) WEPopoverController *popoverController;

- (IBAction)showPopover:(id)sender;

@end
Loading