Skip to content

Instantly share code, notes, and snippets.

@AlexAstroCat
Created September 19, 2010 19:23
Show Gist options
  • Save AlexAstroCat/587039 to your computer and use it in GitHub Desktop.
Save AlexAstroCat/587039 to your computer and use it in GitHub Desktop.
//
// DNCloseButton.h
// ParkingMobility
//
// Created by Michael Nachbaur on 10-08-22.
// Copyright 2010 Decaf Ninja Software. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface DNCloseButton : UIButton {
}
@end
//
// DNCloseButton.m
// ParkingMobility
//
// Created by Michael Nachbaur on 10-08-22.
// Copyright 2010 Decaf Ninja Software. All rights reserved.
//
#import "DNCloseButton.h"
@implementation DNCloseButton
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CGFloat radius = self.bounds.size.width / 2;
CGFloat borderWidth = self.bounds.size.width / 10;
self.layer.backgroundColor = [[UIColor blackColor] CGColor];
self.layer.borderColor = [[UIColor whiteColor] CGColor];
self.layer.borderWidth = borderWidth;
self.layer.cornerRadius = radius;
if ([self.layer respondsToSelector:@selector(setShadowOffset:)])
self.layer.shadowOffset = CGSizeMake(0.25, 0.25);
if ([self.layer respondsToSelector:@selector(setShadowColor:)])
self.layer.shadowColor = [[UIColor blackColor] CGColor];
if ([self.layer respondsToSelector:@selector(setShadowRadius:)])
self.layer.shadowRadius = borderWidth;
if ([self.layer respondsToSelector:@selector(setShadowOpacity:)])
self.layer.shadowOpacity = 0.75;
[self setNeedsDisplay];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(ctx, true);
CGFloat xsize = self.bounds.size.width / 6;
CGFloat borderWidth = self.bounds.size.width / 10;
CGContextSaveGState(ctx);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, borderWidth);
CGContextSetStrokeColorWithColor(ctx, [[UIColor whiteColor] CGColor]);
CGFloat width = self.bounds.size.width;
CGPoint start1 = CGPointMake(width / 2 - xsize, width / 2 - xsize);
CGPoint end1 = CGPointMake(width / 2 + xsize, width / 2 + xsize);
CGPoint start2 = CGPointMake(width / 2 + xsize, width / 2 - xsize);
CGPoint end2 = CGPointMake(width / 2 - xsize, width / 2 + xsize);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, start1.x, start1.y);
CGContextAddLineToPoint(ctx, end1.x, end1.y);
CGContextStrokePath(ctx);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, start2.x, start2.y);
CGContextAddLineToPoint(ctx, end2.x, end2.y);
CGContextStrokePath(ctx);
CGContextRestoreGState(ctx);
}
@end
CGFloat closeSize = 26.0;
CGRect butframe = CGRectMake(0.0, 0.0, closeSize, closeSize);
butframe.origin.x = contentView.frame.origin.x - closeSize / 2;
butframe.origin.y = contentView.frame.origin.y - closeSize / 2;
DNCloseButton *button = [[[DNCloseButton alloc] initWithFrame:butframe] autorelease];
[button addTarget:self action:@selector(closePopup:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment