Created
October 30, 2014 10:05
-
-
Save spraveenk91/631b7c2b8e3d0afed7a0 to your computer and use it in GitHub Desktop.
BaseViewController Main File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BaseViewController.m | |
// | |
// Created by Work on 22/09/14. | |
// Copyright (c) 2014 E. All rights reserved. | |
// | |
#import "BaseViewController.h" | |
#import "GlobalInstance.h" | |
#import "CDRTranslucentSideBar.h" | |
@interface BaseViewController () <CDRTranslucentSideBarDelegate> | |
@property (nonatomic, strong) CDRTranslucentSideBar *sideBar; | |
@end | |
@implementation BaseViewController { | |
UIActionSheet *menuActionSheet; | |
NSMutableArray *menuTableRecords; | |
} | |
#pragma mark - Actions | |
- (void)showMenuView { | |
[self.sideBar show]; | |
} | |
- (void)searchPage { | |
} | |
- (void)menuMore { | |
[[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Browse All", @"Coming Soon", @"Filter", nil] showInView:[self.view window]]; | |
} | |
#pragma mark - UIActionSheet Delegate | |
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { | |
if ([[self delegate] respondsToSelector:@selector(didSelectActionSheetIndex:actionSheetIndex:)]) { | |
[[self delegate] didSelectActionSheetIndex:[actionSheet buttonTitleAtIndex:buttonIndex] actionSheetIndex:buttonIndex]; | |
} | |
} | |
- (void)actionSheetCancel:(UIActionSheet *)actionSheet { | |
NSLog(@"Dismissed"); | |
} | |
// This is just a sample for tableview menu | |
#pragma mark - UITableViewDataSource | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return [menuTableRecords count]; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
return 44.0f; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; | |
cell.backgroundColor = [UIColor clearColor]; | |
cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
} | |
cell.imageView.image = [UIImage imageNamed:@"a_facebook.png"]; | |
cell.textLabel.text = [menuTableRecords objectAtIndex:indexPath.row]; | |
cell.textLabel.font = [UIFont systemFontOfSize:12.0f]; | |
cell.textLabel.textColor = [UIColor whiteColor]; | |
return cell; | |
} | |
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { | |
tableView.separatorStyle = UITableViewCellSeparatorStyleNone; | |
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; | |
} | |
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath { | |
tableView.separatorStyle = UITableViewCellSeparatorStyleNone; | |
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; | |
} | |
#pragma mark - Gesture Handler | |
- (void)handlePanGesture:(UIPanGestureRecognizer *)recognizer { | |
// if you have left and right sidebar, you can control the pan gesture by start point. | |
if (recognizer.state == UIGestureRecognizerStateBegan) { | |
CGPoint startPoint = [recognizer locationInView:self.view]; | |
// Left SideBar | |
if (startPoint.x < self.view.bounds.size.width / 2.0) { | |
self.sideBar.isCurrentPanGestureTarget = YES; | |
} | |
} | |
[self.sideBar handlePanGestureToShow:recognizer inView:self.view]; | |
// if you have only one sidebar, do like following | |
// self.sideBar.isCurrentPanGestureTarget = YES; | |
//[self.sideBar handlePanGestureToShow:recognizer inView:self.view]; | |
} | |
#pragma mark - View Lifecycle | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
menuTableRecords = [NSMutableArray arrayWithArray:[NSArray arrayWithObjects:@"PROFILE", @"SETING", @"DEVICES", @"MY WATCHLIST", @"MY PLAYLISTS", @"MORE", nil]]; | |
self.sideBar = [[CDRTranslucentSideBar alloc] init]; | |
self.sideBar.sideBarWidth = 200; | |
self.sideBar.delegate = self; | |
self.sideBar.tag = 0; | |
// Add PanGesture to Show SideBar by PanGesture | |
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; | |
[[self.view window] addGestureRecognizer:panGestureRecognizer]; | |
// Create Content of SideBar | |
UITableView *tableView = [[UITableView alloc] init]; | |
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.height)]; | |
v.backgroundColor = [UIColor redColor]; | |
tableView.tableHeaderView = ({ | |
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 225.0f)]; | |
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 70, 45.0, 45.0)]; | |
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; | |
imageView.image = [UIImage imageNamed:@"icon"]; | |
imageView.layer.masksToBounds = YES; | |
imageView.layer.cornerRadius = 25.0f; | |
imageView.layer.borderColor = [UIColor whiteColor].CGColor; | |
imageView.layer.borderWidth = 1.5f; | |
imageView.layer.rasterizationScale = [UIScreen mainScreen].scale; | |
imageView.layer.shouldRasterize = YES; | |
imageView.clipsToBounds = YES; | |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 125.0, 0, 20.0)]; | |
label.text = @"Eros International"; | |
label.font = [UIFont fontWithName:@"HelveticaNeue" size:14.0]; | |
label.backgroundColor = [UIColor clearColor]; | |
label.textColor = [UIColor blackColor]; | |
[label sizeToFit]; | |
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; | |
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 155.0, 0, 20.0)]; | |
label1.text = @"[email protected]"; | |
label1.font = [UIFont fontWithName:@"HelveticaNeue" size:12.0]; | |
label1.backgroundColor = [UIColor clearColor]; | |
label1.textColor = [UIColor blackColor]; | |
[label1 sizeToFit]; | |
label1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; | |
[view addSubview:imageView]; | |
[view addSubview:label]; | |
[view addSubview:label1]; | |
view; | |
}); | |
//If you create UITableViewController and set datasource or delegate to it, don't forget to add childcontroller to this viewController. | |
//[[self addChildViewController: @"your view controller"]; | |
tableView.dataSource = self; | |
tableView.delegate = self; | |
tableView.backgroundColor = RGBAColor(37.0, 37.0, 37.0, 1.0); | |
// Set ContentView in SideBar | |
[self.sideBar setContentViewInSideBar:tableView]; | |
} | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[self customBarButton:[UIImage imageNamed:@"option"] targetMethod:@selector(showMenuView)]]; | |
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithCustomView:[self customBarButton:[UIImage imageNamed:@"more"] targetMethod:@selector(menuMore)]], FIXED_SPACE, [[UIBarButtonItem alloc] initWithCustomView:[self customBarButton:[UIImage imageNamed:@"searchicon"] targetMethod:@selector(searchPage)]], nil]; | |
} | |
- (UIButton *)customBarButton:(UIImage *)image targetMethod:(SEL)selector { | |
CGRect buttonFrame = CGRectMake(0, 0, image.size.width, image.size.height); | |
UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame]; | |
[button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside]; | |
// [button setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; | |
[button setImage:image forState:UIControlStateNormal]; | |
return button; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
/* | |
#pragma mark - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
// Get the new view controller using [segue destinationViewController]. | |
// Pass the selected object to the new view controller. | |
} | |
*/ | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment