├── .gitignore ├── CAPopUpViewController.jpg ├── Classes ├── CAPopUpViewController.h └── CAPopUpViewController.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /CAPopUpViewController.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iMokhles/CAPopUpViewController/a081631cebcb598deb8e2f772d1d5646b74a3c8e/CAPopUpViewController.jpg -------------------------------------------------------------------------------- /Classes/CAPopUpViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CAPopUpViewController.h 3 | // ContrAlert 4 | // 5 | // Created by Mokhlas Hussein on 16/09/15. 6 | // Copyright © 2015 iMokhles. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CAPopUpViewController : UIViewController 12 | 13 | // popover source view 14 | @property (nonatomic, strong) UIView *sourceView; 15 | 16 | // menu items array 17 | @property (nonatomic, strong) NSArray *itemsArray; 18 | 19 | // set background image 20 | @property (nonatomic, strong) UIImage *backgroundImage; 21 | 22 | // set to clear if you set the backgroundImage 23 | @property (nonatomic, strong) UIColor *backgroundColor; 24 | 25 | // item title color 26 | @property (nonatomic, strong) UIColor *itemTitleColor; 27 | 28 | // item selection background 29 | @property (nonatomic, strong) UIColor *itemSelectionColor; 30 | 31 | // popover arrow direction 32 | @property (nonatomic, assign) UIPopoverArrowDirection arrowDirections; 33 | 34 | // popover arrow color 35 | @property (nonatomic, strong) UIColor *arrowColor; 36 | 37 | // item cell tapped block 38 | @property (nonatomic, copy) void (^popCellBlock)(CAPopUpViewController * popupVC, UITableViewCell *popCell, NSInteger row, NSInteger section); 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Classes/CAPopUpViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CAPopUpViewController.m 3 | // ContrAlert 4 | // 5 | // Created by Mokhlas Hussein on 16/09/15. 6 | // Copyright © 2015 iMokhles. All rights reserved. 7 | // 8 | 9 | #import "CAPopUpViewController.h" 10 | 11 | @interface CAPopUpViewController () 12 | 13 | @property (nonatomic, strong) UITableView *tableView; 14 | @end 15 | 16 | @implementation CAPopUpViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | self.view.frame = CGRectMake(0, 0, 230, (self.itemsArray.count*44)); 22 | self.preferredContentSize = CGSizeMake(230, (self.itemsArray.count*44)); 23 | self.popoverPresentationController.sourceView = self.sourceView; 24 | self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; 25 | self.tableView.delegate = self; 26 | self.tableView.dataSource = self; 27 | self.tableView.scrollEnabled = NO; 28 | self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 29 | [self.view addSubview:self.tableView]; 30 | 31 | if (self.backgroundImage != nil && self.backgroundColor == nil) { 32 | UIImageView *tempImageView = [[UIImageView alloc] initWithImage:self.backgroundImage]; 33 | [tempImageView setFrame:self.tableView.frame]; 34 | self.tableView.backgroundView = tempImageView; 35 | self.tableView.backgroundColor = [UIColor clearColor]; 36 | } else if (self.backgroundImage != nil && self.backgroundColor != nil) { 37 | UIImageView *tempImageView = [[UIImageView alloc] initWithImage:self.backgroundImage]; 38 | [tempImageView setFrame:self.tableView.frame]; 39 | self.tableView.backgroundView = tempImageView; 40 | self.tableView.backgroundColor = [UIColor clearColor]; 41 | } else if (self.backgroundImage == nil && self.backgroundColor != nil) { 42 | self.tableView.backgroundColor = self.backgroundColor; 43 | } else { 44 | 45 | self.tableView.backgroundColor = [UIColor whiteColor]; 46 | } 47 | 48 | 49 | self.popoverPresentationController.sourceRect = CGRectMake(0, 0, 230, 30); 50 | self.popoverPresentationController.permittedArrowDirections = self.arrowDirections; 51 | self.popoverPresentationController.backgroundColor = [UIColor whiteColor]; 52 | 53 | if (self.arrowColor != nil) { 54 | self.popoverPresentationController.backgroundColor = self.arrowColor; 55 | } 56 | [self.tableView reloadData]; 57 | } 58 | - (void)viewDidAppear:(BOOL)animated { 59 | [super viewDidAppear:animated]; 60 | [self.tableView reloadData]; 61 | } 62 | 63 | - (id)init { 64 | if (self == [super initWithNibName:nil bundle:nil]) { 65 | self.modalPresentationStyle = UIModalPresentationPopover; 66 | self.popoverPresentationController.delegate = self; 67 | } 68 | return self; 69 | } 70 | 71 | -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{ 72 | return UIModalPresentationNone; 73 | } 74 | 75 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 76 | return 1; 77 | } 78 | 79 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 80 | return self.itemsArray.count; 81 | } 82 | 83 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 84 | 85 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"popupCell"]; 86 | if (cell == nil) { 87 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"popupCell"]; 88 | } 89 | 90 | cell.textLabel.text = self.itemsArray[indexPath.row]; 91 | return cell; 92 | } 93 | 94 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 95 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 96 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 97 | if (self.popCellBlock != nil) { 98 | self.popCellBlock(self, cell, indexPath.row, indexPath.section); 99 | } 100 | } 101 | 102 | - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 103 | cell.textLabel.textColor = [UIColor whiteColor]; 104 | 105 | if (self.itemTitleColor != nil) { 106 | cell.textLabel.textColor = self.itemTitleColor; 107 | } 108 | 109 | if (self.backgroundImage == nil && self.backgroundColor == nil) { 110 | cell.textLabel.textColor = [UIColor blackColor]; 111 | } 112 | 113 | [cell.textLabel setTextAlignment:NSTextAlignmentCenter]; 114 | cell.backgroundColor = [UIColor clearColor]; 115 | cell.contentView.backgroundColor = [UIColor clearColor]; 116 | 117 | UIView * additionalSeparator = [[UIView alloc] initWithFrame:CGRectMake(0,cell.frame.size.height,cell.frame.size.width,1)]; 118 | additionalSeparator.backgroundColor = [UIColor lightGrayColor]; 119 | [cell addSubview:additionalSeparator]; 120 | 121 | UIView *bgColorView = [[UIView alloc] init]; 122 | bgColorView.backgroundColor = [UIColor lightGrayColor]; 123 | if (self.itemSelectionColor != nil) { 124 | bgColorView.backgroundColor = self.itemSelectionColor; //[UIColor hex:@"283146"]; 125 | } 126 | 127 | [cell setSelectedBackgroundView:bgColorView]; 128 | cell.textLabel.alpha = 1.0; 129 | 130 | } 131 | 132 | @end 133 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Mokhlas Hussein 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CAPopUpViewController 2 | is a simple popup menu see screenshot for more info 3 | 4 | [![Version](https://img.shields.io/cocoapods/v/CAPopUpViewController.svg?style=flat)](http://cocoadocs.org/docsets/CAPopUpViewController) 5 | [![License](https://img.shields.io/cocoapods/l/CAPopUpViewController.svg?style=flat)](http://cocoadocs.org/docsets/CAPopUpViewController) 6 | [![Platform](https://img.shields.io/cocoapods/p/CAPopUpViewController.svg?style=flat)](http://cocoadocs.org/docsets/CAPopUpViewController) 7 | 8 |

9 | 10 |

11 | 12 | ### Usage 13 | 14 | CAPopUpViewController available through [CocoaPods](http://cocoapods.org). To install 15 | it, add the following line to your Podfile: 16 | 17 | pod "CAPopUpViewController" 18 | 19 | or drag the files manually then import it 20 | 21 | #import "CAPopUpViewController.h" 22 | 23 | ### Example 24 | 25 | NSString *sendName = [[NSBundle mainBundle] localizedStringForKey:@"Send" value:@"" table:nil]; 26 | NSString *schuName = [[NSBundle mainBundle] localizedStringForKey:@"Schedule" value:@"" table:nil]; 27 | 28 | dispatch_async(dispatch_get_main_queue(), ^{ 29 | CAPopUpViewController *popup = [[CAPopUpViewController alloc] init]; 30 | popup.itemsArray = @[sendName, schuName]; 31 | popup.sourceView = self.contentView.sendButton; 32 | popup.backgroundColor = [UIColor whiteColor]; 33 | popup.backgroundImage = nil; 34 | popup.itemTitleColor = [UIColor blackColor]; 35 | popup.itemSelectionColor = [UIColor lightGrayColor]; 36 | popup.arrowDirections = UIPopoverArrowDirectionAny; 37 | popup.arrowColor = [UIColor whiteColor]; 38 | [popup setPopCellBlock:^(CAPopUpViewController *popupVC, UITableViewCell *popupCell, NSInteger row, NSInteger section) { 39 | if ([popupCell.textLabel.text isEqualToString:sendName]) { 40 | dispatch_async(dispatch_get_main_queue(), ^{ 41 | [popupVC dismissViewControllerAnimated:YES completion:^{ 42 | 43 | }]; 44 | }); 45 | 46 | } else if ([popupCell.textLabel.text isEqualToString:schuName]) { 47 | dispatch_async(dispatch_get_main_queue(), ^{ 48 | 49 | [popupVC dismissViewControllerAnimated:YES completion:^{ 50 | 51 | }]; 52 | }); 53 | } 54 | }]; 55 | [self.delegate presentViewController:popup animated:YES completion:^{ 56 | 57 | }]; 58 | }); 59 | 60 | ## Author 61 | 62 | [Mokhlas Hussein (iMokhles)](https://twitter.com/imokhles), [mokhleshussien@gmail.com](mailto:mokhleshussien@aol.com) 63 | 64 | ### License 65 | 66 | Copyright (c) 2016, Mokhlas Hussein 67 | All rights reserved. 68 | 69 | Redistribution and use in source and binary forms, with or without 70 | modification, are permitted provided that the following conditions are met: 71 | 72 | * Redistributions of source code must retain the above copyright notice, this 73 | list of conditions and the following disclaimer. 74 | 75 | * Redistributions in binary form must reproduce the above copyright notice, 76 | this list of conditions and the following disclaimer in the documentation 77 | and/or other materials provided with the distribution. 78 | 79 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 80 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 81 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 82 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 83 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 84 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 85 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 86 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 87 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 88 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 89 | --------------------------------------------------------------------------------