Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
First commit after removing images
Browse files Browse the repository at this point in the history
  • Loading branch information
MugunthKumar committed Mar 2, 2012
0 parents commit 9d07f8b
Show file tree
Hide file tree
Showing 15 changed files with 6,426 additions and 0 deletions.
60 changes: 60 additions & 0 deletions MKInfoBundle/MKInfoPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// MKInfoPanel.h
// HorizontalMenu
//
// Created by Mugunth on 25/04/11.
// Copyright 2011 Steinlogic. All rights reserved.
// Permission granted to do anything, commercial/non-commercial with this file apart from removing the line/URL above
// Read my blog post at http://mk.sg/8e on how to use this code

// As a side note on using this code, you might consider giving some credit to me by
// 1) linking my website from your app's website
// 2) or crediting me inside the app's credits page
// 3) or a tweet mentioning @mugunthkumar
// 4) A paypal donation to mugunth.kumar@gmail.com
//
// A note on redistribution
// While I'm ok with modifications to this source code,
// if you are re-publishing after editing, please retain the above copyright notices

#import <UIKit/UIKit.h>
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

typedef enum {
MKInfoPanelTypeInfo,
MKInfoPanelTypeError
} MKInfoPanelType;

@interface MKInfoPanel : UIView {

UILabel *_titleLabel;
UILabel *_detailLabel;

UIImageView *_thumbImage;
UIImageView *_backgroundGradient;

SEL _onTouched;

id _delegate;
SEL _onFinished;

MKInfoPanelType type_;
}

@property (nonatomic, assign) IBOutlet UILabel *titleLabel;
@property (nonatomic, assign) IBOutlet UILabel *detailLabel;
@property (nonatomic, assign) IBOutlet UIImageView *thumbImage;
@property (nonatomic, assign) IBOutlet UIImageView *backgroundGradient;
@property (nonatomic, assign) SEL onTouched;
@property (nonatomic, assign) id delegate;
@property (nonatomic, assign) SEL onFinished;

+ (MKInfoPanel *)showPanelInView:(UIView*)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle;
+ (MKInfoPanel *)showPanelInView:(UIView*)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval;

+ (MKInfoPanel *)showPanelInWindow:(UIWindow*)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle;
+ (MKInfoPanel *)showPanelInWindow:(UIWindow*)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval;

- (void)hidePanel;

@end
200 changes: 200 additions & 0 deletions MKInfoBundle/MKInfoPanel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
//
// MKInfoPanel.m
// HorizontalMenu
//
// Created by Mugunth on 25/04/11.
// Copyright 2011 Steinlogic. All rights reserved.
// Permission granted to do anything, commercial/non-commercial with this file apart from removing the line/URL above
// Read my blog post at http://mk.sg/8e on how to use this code

// As a side note on using this code, you might consider giving some credit to me by
// 1) linking my website from your app's website
// 2) or crediting me inside the app's credits page
// 3) or a tweet mentioning @mugunthkumar
// 4) A paypal donation to mugunth.kumar@gmail.com
//
// A note on redistribution
// While I'm ok with modifications to this source code,
// if you are re-publishing after editing, please retain the above copyright notices

#import "MKInfoPanel.h"
#import <QuartzCore/QuartzCore.h>

// Private Methods

@interface MKInfoPanel ()

@property (nonatomic, assign) MKInfoPanelType type;

+ (MKInfoPanel*) infoPanel;

- (void)setup;

@end


@implementation MKInfoPanel

@synthesize titleLabel = _titleLabel;
@synthesize detailLabel = _detailLabel;
@synthesize thumbImage = _thumbImage;
@synthesize backgroundGradient = _backgroundGradient;
@synthesize onTouched = _onTouched;
@synthesize delegate = _delegate;
@synthesize onFinished = _onFinished;
@synthesize type = type_;


////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Lifecycle
////////////////////////////////////////////////////////////////////////

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}

- (void)dealloc {
[_delegate performSelector:_onFinished];

[super dealloc];
}

////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Setter/Getter
////////////////////////////////////////////////////////////////////////

-(void)setType:(MKInfoPanelType)type {
if(type == MKInfoPanelTypeError) {
self.backgroundGradient.image = [[UIImage imageNamed:@"Red"] stretchableImageWithLeftCapWidth:1 topCapHeight:5];
self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
self.detailLabel.font = [UIFont fontWithName:@"Helvetica Neue"
size:14];
self.thumbImage.image = [UIImage imageNamed:@"Warning"];
self.detailLabel.textColor = [UIColor colorWithRed:1.f green:0.651f blue:0.651f alpha:1.f];
}

else if(type == MKInfoPanelTypeInfo) {
self.backgroundGradient.image = [[UIImage imageNamed:@"Blue"] stretchableImageWithLeftCapWidth:1 topCapHeight:5];
self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
self.thumbImage.image = [UIImage imageNamed:@"Tick"];
self.detailLabel.textColor = RGBA(210, 210, 235, 1.0);
}
}

////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Show/Hide
////////////////////////////////////////////////////////////////////////

+ (MKInfoPanel *)showPanelInView:(UIView *)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle {
return [self showPanelInView:view type:type title:title subtitle:subtitle hideAfter:-1];
}

+(MKInfoPanel *)showPanelInView:(UIView *)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval {
MKInfoPanel *panel = [MKInfoPanel infoPanel];
CGFloat panelHeight = 50; // panel height when no subtitle set

panel.type = type;
panel.titleLabel.text = title;

if(subtitle) {
panel.detailLabel.text = subtitle;
[panel.detailLabel sizeToFit];

panelHeight = MAX(CGRectGetMaxY(panel.thumbImage.frame), CGRectGetMaxY(panel.detailLabel.frame));
panelHeight += 10.f; // padding at bottom
} else {
panel.detailLabel.hidden = YES;
panel.thumbImage.frame = CGRectMake(15, 5, 35, 35);
panel.titleLabel.frame = CGRectMake(57, 12, 240, 21);
}

// update frame of panel
panel.frame = CGRectMake(0, 0, view.bounds.size.width, panelHeight);
[view addSubview:panel];

if (interval > 0) {
[panel performSelector:@selector(hidePanel) withObject:view afterDelay:interval];
}

return panel;
}

+ (MKInfoPanel *)showPanelInWindow:(UIWindow *)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle {
return [self showPanelInWindow:window type:type title:title subtitle:subtitle hideAfter:-1];
}

+(MKInfoPanel *)showPanelInWindow:(UIWindow *)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval {
MKInfoPanel *panel = [self showPanelInView:window type:type title:title subtitle:subtitle hideAfter:interval];

if (![UIApplication sharedApplication].statusBarHidden) {
CGRect frame = panel.frame;
frame.origin.y += [UIApplication sharedApplication].statusBarFrame.size.height;
panel.frame = frame;
}

return panel;
}

-(void)hidePanel {
[NSObject cancelPreviousPerformRequestsWithTarget:self];

CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.layer addAnimation:transition forKey:nil];
self.frame = CGRectMake(0, -self.frame.size.height, self.frame.size.width, self.frame.size.height);

[self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.25];
}

////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Touch Recognition
////////////////////////////////////////////////////////////////////////

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self performSelector:_onTouched];
}

////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Private
////////////////////////////////////////////////////////////////////////

+(MKInfoPanel *)infoPanel {
MKInfoPanel *panel = (MKInfoPanel*) [[[UINib nibWithNibName:@"MKInfoPanel" bundle:nil]
instantiateWithOwner:self options:nil] objectAtIndex:0];

CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
[panel.layer addAnimation:transition forKey:nil];

return panel;
}

- (void)setup {
self.onTouched = @selector(hidePanel);
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
}

@end
Loading

1 comment on commit 9d07f8b

@davebcn87
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the images?

Please sign in to comment.