forked from sumanthk2006/MBAlertView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMBAlertViewButton.m
More file actions
70 lines (58 loc) · 2.13 KB
/
MBAlertViewButton.m
File metadata and controls
70 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// MBAlertViewButton.m
// Notestand
//
// Created by M B. Bitar on 9/8/12.
// Copyright (c) 2012 progenius, inc. All rights reserved.
//
#import "MBAlertViewButton.h"
#import <QuartzCore/QuartzCore.h>
#import "AlertViewUI.h"
@implementation MBAlertViewButton
#define kShadowSize 8
#define kButtonFont [UIFont boldSystemFontOfSize:18]
- (id)initWithTitle:(NSString*)title
{
self = [super initWithFrame:CGRectMake(0, 0, 100, 40)];
if (self) {
[self setBackgroundColor:[UIColor clearColor]];
_title = title;
}
return self;
}
-(UIColor*)colorForButtonStyle
{
if(_alertButtonType == MBAlertViewItemTypeDefault) {
return [UIColor whiteColor];
} else if(_alertButtonType == MBAlertViewItemTypeDestructive) {
return [UIColor redColor];
} else if(_alertButtonType == MBAlertViewItemTypePositive) {
return BLUE_GLOW_COLOR;
}
return [UIColor whiteColor];
}
-(UIColor*)textColor
{
if(_alertButtonType == MBAlertViewItemTypeDefault) {
return [UIColor colorWithWhite:0.2 alpha:1.0];
} else if(_alertButtonType == MBAlertViewItemTypeDestructive) {
return [UIColor whiteColor];
} else if(_alertButtonType == MBAlertViewItemTypePositive) {
return [UIColor whiteColor];
}
return [UIColor whiteColor];
}
- (void)drawRect:(CGRect)rect
{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:2.0];
[[self colorForButtonStyle] setFill];
[path fill];
float actualSize = 0;
[_title sizeWithFont:kButtonFont minFontSize:8 actualFontSize:&actualSize forWidth:self.bounds.size.width - 20 lineBreakMode:NSLineBreakByClipping];
CGSize otherSize = [_title sizeWithFont:[UIFont boldSystemFontOfSize:actualSize]];
CGPoint origin = CGPointMake(self.bounds.size.width/2.0 - otherSize.width/2.0, self.bounds.size.height/2.0 - otherSize.height/2.0);
CGRect frame = CGRectMake(origin.x, origin.y, otherSize.width, otherSize.height);
[[self textColor] set];
[_title drawInRect:frame withFont:[UIFont boldSystemFontOfSize:actualSize] lineBreakMode:NSLineBreakByClipping];
}
@end