Skip to content

Commit

Permalink
Added Custom UIAlertView
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelspring committed Dec 29, 2011
1 parent d073edd commit 9904767
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 153 deletions.
17 changes: 0 additions & 17 deletions Classes/CustomAlert.h

This file was deleted.

115 changes: 0 additions & 115 deletions Classes/CustomAlert.m

This file was deleted.

10 changes: 7 additions & 3 deletions Classes/ObjC_MixAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
}

//sleep(10); // Delay App start by holding the Default.png for 10 seconds
// Enable Safari's Web Inspector for iOS 5 using a conditional, as app will throw a hissy fit & crash if lower than iOS 5 :)
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5) {
[NSClassFromString(@"WebView") _enableRemoteInspector];
}

//sleep(10); // Delay App start by holding the Default.png for 10 seconds

// Fancy Fade/Zoom After Load
//*********************************
Expand All @@ -51,11 +56,10 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
splashView.alpha = 0.0;
//splashView.frame = CGRectMake(-60, -85, 440, 635); // Comment this out (or change dimension to match initWithFrame) for fade without zoom.
[UIView commitAnimations];

}




/*
this is the method in charge to remove the detectos
it receives a string (the name of the page) you want to remove the detectors
Expand Down
22 changes: 22 additions & 0 deletions Classes/customUIAlert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// customUIAlert.h
// ObjC-Mix
//
// Created by Mike Seaby on 29/12/2011.
// Copyright (c) 2011 Mike Seaby. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface customUIAlert : UIAlertView
{
UIWebView *_webView;
NSString *_currentPage;
NSDictionary* _parameters;
}

@property (nonatomic, assign) UIWebView *_webView;
@property (retain) NSString *_currentPage;
@property(retain) NSDictionary* _parameters;

@end
174 changes: 174 additions & 0 deletions Classes/customUIAlert.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
//
// customUIAlert.m
// ObjC-Mix
//
// Created by Mike Seaby on 29/12/2011.
// Copyright (c) 2011 Mike Seaby. All rights reserved.
//

#import "customUIAlert.h"
#import "NKBridge.h"
#import "Nimble.h"
#import <QuartzCore/QuartzCore.h>

@implementation customUIAlert
@synthesize _webView, _currentPage, _parameters;

-(void)customAlert
{
NSLog(@"Custom Alert Called");

customUIAlert *customAlertView = [[customUIAlert alloc] initWithTitle:[_parameters objectForKey:@"title"]
message:[_parameters objectForKey:@"message"]
delegate:self
cancelButtonTitle:[_parameters objectForKey:@"cancel"]
otherButtonTitles:[_parameters objectForKey:@"ok"],nil];

[customAlertView show];
[customAlertView release];
}

- (void)layoutSubviews
{
for (UIView *subview in self.subviews){
if ([subview isMemberOfClass:[UIImageView class]]) {
subview.hidden = YES; //Hide UIImageView Containing Blue Background
}

if ([subview isMemberOfClass:[UILabel class]]) { // Point to UILabels To Change Text
UILabel *label = (UILabel*)subview; // Cast From UIView to UILabel
label.textColor = [UIColor colorWithRed:210.0f/255.0f green:210.0f/255.0f blue:210.0f/255.0f alpha:1.0f];
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(0.0f, 1.0f);
}
}
}


- (void)drawRect:(CGRect)rect {

//---------------------------------------------------------------------------------------------------

// Image
//UIImage *image = [UIImage imageNamed:@"wbg.png"];
//[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

//---------------------------------------------------------------------------------------------------



// Reference the Current Graphics Context
CGContextRef context = UIGraphicsGetCurrentContext();

// Create a Base Shape
CGRect activeBounds = self.bounds;
CGFloat cornerRadius = 10.0f; // How round do you like your corners? (Try -2.0f for that wonky look!)
CGFloat inset = 2.5f; // Set that inset. Higher values = less padding.
CGFloat originX = activeBounds.origin.x + inset;
CGFloat originY = activeBounds.origin.y + inset;
CGFloat width = activeBounds.size.width - (inset*2.0f);
CGFloat height = activeBounds.size.height - (inset*2.0f);

CGRect bPathFrame = CGRectMake(originX, originY, width, height);
CGPathRef path = [UIBezierPath bezierPathWithRoundedRect:bPathFrame cornerRadius:cornerRadius].CGPath;

// Add Fill and Outer Drop Shadow
CGContextAddPath(context, path);
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:210.0f/255.0f green:210.0f/255.0f blue:210.0f/255.0f alpha:1.0f].CGColor);
CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 1.0f), 6.0f, [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0f].CGColor);
CGContextDrawPath(context, kCGPathFill);

// Clip the Context
CGContextSaveGState(context); //Save Context State Before Clipping To "path"
CGContextAddPath(context, path);
CGContextClip(context);

// Draw Gradient
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
size_t count = 3;
CGFloat locations[3] = {0.0f, 0.57f, 1.0f};
CGFloat components[12] =
{
70.0f/255.0f, 70.0f/255.0f, 70.0f/255.0f, 1.0f, //1
55.0f/255.0f, 55.0f/255.0f, 55.0f/255.0f, 1.0f, //2
40.0f/255.0f, 40.0f/255.0f, 40.0f/255.0f, 1.0f //3
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, count);
CGPoint startPoint = CGPointMake(activeBounds.size.width * 0.5f, 0.0f);
CGPoint endPoint = CGPointMake(activeBounds.size.width * 0.5f, activeBounds.size.height);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);

// Hatched Background
CGFloat buttonOffset = 0.5f; // Offset by half point for crisp lines. Change this value to move hatched area down - try 92.5 for instance
CGContextSaveGState(context); // Save Context State Before Clipping "hatchPath"
CGRect hatchFrame = CGRectMake(0.0f, buttonOffset, activeBounds.size.width, (activeBounds.size.height - buttonOffset+1.0f));
CGContextClipToRect(context, hatchFrame);

CGFloat spacer = 4.0f;
int rows = (activeBounds.size.width + activeBounds.size.height/spacer);
CGFloat padding = 0.0f;
CGMutablePathRef hatchPath = CGPathCreateMutable();
for(int i=1; i<=rows; i++) {
CGPathMoveToPoint(hatchPath, NULL, spacer * i, padding);
CGPathAddLineToPoint(hatchPath, NULL, padding, spacer * i);
}
CGContextAddPath(context, hatchPath);
CGPathRelease(hatchPath);
CGContextSetLineWidth(context, 1.0f);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.35f].CGColor);
CGContextDrawPath(context, kCGPathStroke);

// Draw A Separating Line
CGMutablePathRef linePath = CGPathCreateMutable();
CGFloat linePathY = (buttonOffset - 1.0f);
CGPathMoveToPoint(linePath, NULL, 0.0f, linePathY);
CGPathAddLineToPoint(linePath, NULL, activeBounds.size.width, linePathY);
CGContextAddPath(context, linePath);
CGPathRelease(linePath);
CGContextSetLineWidth(context, 3.0f);
CGContextSaveGState(context); //Save Context State Before Drawing "linePath" Shadow
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.6f].CGColor);
CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 1.0f), 0.0f, [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.2f].CGColor);
CGContextDrawPath(context, kCGPathStroke);
CGContextRestoreGState(context); //Restore Context State After Drawing "linePath" Shadow

// Inner Shadow
CGContextAddPath(context, path);
CGContextSetLineWidth(context, 3.0f);
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:210.0f/255.0f green:210.0f/255.0f blue:210.0f/255.0f alpha:1.0f].CGColor);
CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 0.0f), 6.0f, [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0f].CGColor);
CGContextDrawPath(context, kCGPathStroke);

// Redraw The Path to avoid Pixellation
CGContextRestoreGState(context); //Restore First Context State Before Clipping "path"
CGContextAddPath(context, path);
CGContextSetLineWidth(context, 3.0f);
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:210.0f/255.0f green:210.0f/255.0f blue:210.0f/255.0f alpha:1.0f].CGColor);
CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 0.0f), 0.0f, [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.1f].CGColor);
CGContextDrawPath(context, kCGPathStroke);

}





#pragma mark NK Setters

- (void)setNKWebView:(UIWebView*)view {
self._webView = view;
}

- (void)setNKCurrentPage:(NSString*)page {
self._currentPage = page;
}

- (void)setNKParameters:(NSDictionary*)parameters
{
self._parameters = parameters;
}

@end
Loading

0 comments on commit 9904767

Please sign in to comment.