forked from jasarien/JSScrollableTabBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSTabButton.m
More file actions
87 lines (67 loc) · 2.53 KB
/
JSTabButton.m
File metadata and controls
87 lines (67 loc) · 2.53 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// JSTabButton.m
//
// Created by James Addyman on 29/04/2010.
// Copyright 2010 JamSoft. All rights reserved.
//
#import "JSTabButton.h"
#import "UIImage+JSRetinaAdditions.h"
@implementation JSTabButton
@synthesize toggled = _toggled;
@synthesize normalBg = _normalBg;
@synthesize highlightedBg = _highlightedBg;
+ (JSTabButton *)tabButtonWithTitle:(NSString *)string andColor:(UIColor*)color andTextColor:(UIColor*)textColor
{
NSString *imageBundlePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"images.bundle"];
NSBundle *imageBundle = [NSBundle bundleWithPath:imageBundlePath];
static UIImage *normalButton = nil;
static UIImage *highlightedButton = nil;
if (!normalButton)
{
NSLog(@"setting normal button");
normalButton = [[UIImage imageWithContentsOfResolutionIndependentFile:[imageBundle pathForResource:@"tabButtonNormal" ofType:@"png"]] stretchableImageWithLeftCapWidth:14 topCapHeight:0];
}
if (!highlightedButton)
{
NSLog(@"setting Highlighted button");
highlightedButton = [[UIImage imageWithContentsOfResolutionIndependentFile:[imageBundle pathForResource:@"tabButtonHighlighted" ofType:@"png"]] stretchableImageWithLeftCapWidth:14 topCapHeight:0];
}
JSTabButton *button = (JSTabButton *)[self buttonWithType:UIButtonTypeCustom];
[button setAdjustsImageWhenHighlighted:NO];
[button setTitleColor:textColor forState:UIControlStateNormal];
[button setTitleColor:textColor forState:UIControlStateApplication];
[button setTitleColor:textColor forState:UIControlStateHighlighted];
[button setBackgroundColor:color];
[[button titleLabel] setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
[button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
[[button titleLabel] setLineBreakMode:UILineBreakModeTailTruncation];
[button setTitle:string forState:UIControlStateNormal];
[button sizeToFit];
CGRect frame = [button frame];
frame.size.width += 20;
frame.size.height = 25;
[button setFrame:frame];
[button setToggled:NO];
return button;
}
- (void)setToggled:(BOOL)toggled
{
_toggled = toggled;
if (_toggled)
{
[self setBackgroundImage:self.highlightedBg forState:UIControlStateNormal];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
else
{
[self setBackgroundImage:self.normalBg forState:UIControlStateNormal];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
}
- (void)dealloc
{
self.highlightedBg = nil;
self.normalBg = nil;
[super dealloc];
}
@end