Skip to content

Commit db9b338

Browse files
author
Darcy Liu
committed
add TheElements
1 parent 556ade3 commit db9b338

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6940
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,4 +1398,18 @@ The second scroller simply displays one image, matching its contentSize to the i
13981398

13991399
[URL](https://developer.apple.com/library/ios/#samplecode/Scrolling/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008023)
14001400

1401-
Last Revision: Version 1.1, 2010-06-23
1401+
Last Revision: Version 1.1, 2010-06-23
1402+
1403+
#TheElements#
1404+
1405+
TheElements is a sample application that provides access to the data contained in the Periodic Table of the Elements. The Periodic Table of the Elements catalogs all the known atomic elements in the universe.
1406+
1407+
TheElements provides this data in multiple formats, allowing you to sort the data by name, atomic number, symbol name, and an element's physical state at room temperature.
1408+
1409+
TheElements is structured as a Model-View-Controller application. There is distinct separation of the model data, the views used to present that data, and the controllers which act as a liaison between the model and controller.
1410+
1411+
The application illustrates the following techniques: configuring and responding to selections in a tab bar, displaying information in a tableview using both plain and grouped style table views, using navigation controllers to navigate deeper into a data structure, subclassing UIView, providing a custom UITableViewCell consisting of multiple subviews, implementing the UITableViewDelegate protocol, implementing the UITableViewDataSource protocol, reacting to taps in views, open a URL to an external web site using Safari, flipping view content from front to back, and creating a reflection of a view in the interface.
1412+
1413+
[URL](https://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007419)
1414+
1415+
Last Revision: Version 1.11, 2010-06-23

TheElements.zip

539 KB
Binary file not shown.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
File: AtomicElement.h
3+
Abstract: Simple object that encapsulate the Atomic Element values and images for the states.
4+
Version: 1.11
5+
6+
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
7+
Inc. ("Apple") in consideration of your agreement to the following
8+
terms, and your use, installation, modification or redistribution of
9+
this Apple software constitutes acceptance of these terms. If you do
10+
not agree with these terms, please do not use, install, modify or
11+
redistribute this Apple software.
12+
13+
In consideration of your agreement to abide by the following terms, and
14+
subject to these terms, Apple grants you a personal, non-exclusive
15+
license, under Apple's copyrights in this original Apple software (the
16+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
17+
Software, with or without modifications, in source and/or binary forms;
18+
provided that if you redistribute the Apple Software in its entirety and
19+
without modifications, you must retain this notice and the following
20+
text and disclaimers in all such redistributions of the Apple Software.
21+
Neither the name, trademarks, service marks or logos of Apple Inc. may
22+
be used to endorse or promote products derived from the Apple Software
23+
without specific prior written permission from Apple. Except as
24+
expressly stated in this notice, no other rights or licenses, express or
25+
implied, are granted by Apple herein, including but not limited to any
26+
patent rights that may be infringed by your derivative works or by other
27+
works in which the Apple Software may be incorporated.
28+
29+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
30+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34+
35+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42+
POSSIBILITY OF SUCH DAMAGE.
43+
44+
Copyright (C) 2010 Apple Inc. All Rights Reserved.
45+
46+
*/
47+
48+
#import <Foundation/Foundation.h>
49+
50+
51+
@interface AtomicElement : NSObject {
52+
NSNumber *atomicNumber;
53+
NSString *name;
54+
NSString *symbol;
55+
NSString *state;
56+
NSNumber *group;
57+
NSNumber *period;
58+
NSNumber *vertPos;
59+
NSNumber *horizPos;
60+
BOOL radioactive;
61+
NSString *atomicWeight;
62+
NSString *discoveryYear;
63+
64+
}
65+
66+
- (id)initWithDictionary:(NSDictionary *)aDictionary;
67+
68+
@property (nonatomic, retain) NSNumber *atomicNumber;
69+
@property (nonatomic, retain) NSString *name;
70+
@property (nonatomic, retain) NSString *symbol;
71+
@property (nonatomic, retain) NSString *state;
72+
@property (nonatomic, retain) NSNumber *group;
73+
@property (nonatomic, retain) NSNumber *period;
74+
@property (nonatomic, retain) NSNumber *vertPos;
75+
@property (nonatomic, retain) NSNumber *horizPos;
76+
77+
@property (readonly) UIImage *stateImageForAtomicElementTileView;
78+
@property (readonly) UIImage *flipperImageForAtomicElementNavigationItem;
79+
@property (readonly) UIImage *stateImageForAtomicElementView;
80+
@property (readonly) CGPoint positionForElement;
81+
@property BOOL radioactive;
82+
@property (nonatomic, retain) NSString *atomicWeight;
83+
@property (nonatomic, retain) NSString *discoveryYear;
84+
85+
86+
@end
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
File: AtomicElement.m
3+
Abstract: Simple object that encapsulate the Atomic Element values and images for the states.
4+
Version: 1.11
5+
6+
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
7+
Inc. ("Apple") in consideration of your agreement to the following
8+
terms, and your use, installation, modification or redistribution of
9+
this Apple software constitutes acceptance of these terms. If you do
10+
not agree with these terms, please do not use, install, modify or
11+
redistribute this Apple software.
12+
13+
In consideration of your agreement to abide by the following terms, and
14+
subject to these terms, Apple grants you a personal, non-exclusive
15+
license, under Apple's copyrights in this original Apple software (the
16+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
17+
Software, with or without modifications, in source and/or binary forms;
18+
provided that if you redistribute the Apple Software in its entirety and
19+
without modifications, you must retain this notice and the following
20+
text and disclaimers in all such redistributions of the Apple Software.
21+
Neither the name, trademarks, service marks or logos of Apple Inc. may
22+
be used to endorse or promote products derived from the Apple Software
23+
without specific prior written permission from Apple. Except as
24+
expressly stated in this notice, no other rights or licenses, express or
25+
implied, are granted by Apple herein, including but not limited to any
26+
patent rights that may be infringed by your derivative works or by other
27+
works in which the Apple Software may be incorporated.
28+
29+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
30+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34+
35+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42+
POSSIBILITY OF SUCH DAMAGE.
43+
44+
Copyright (C) 2010 Apple Inc. All Rights Reserved.
45+
46+
*/
47+
48+
#import "AtomicElement.h"
49+
50+
51+
@implementation AtomicElement
52+
53+
@synthesize atomicNumber;
54+
@synthesize name;
55+
@synthesize symbol;
56+
@synthesize state;
57+
@synthesize group;
58+
@synthesize period;
59+
@synthesize vertPos;
60+
@synthesize horizPos;
61+
@synthesize radioactive;
62+
@synthesize atomicWeight;
63+
@synthesize discoveryYear;
64+
65+
- (id)initWithDictionary:(NSDictionary *)aDictionary {
66+
if ([self init]) {
67+
self.atomicNumber = [aDictionary valueForKey:@"atomicNumber"];
68+
self.atomicWeight = [aDictionary valueForKey:@"atomicWeight"];
69+
self.discoveryYear = [aDictionary valueForKey:@"discoveryYear"];
70+
self.radioactive = [[aDictionary valueForKey:@"radioactive"] boolValue];
71+
self.name = [aDictionary valueForKey:@"name"];
72+
self.symbol = [aDictionary valueForKey:@"symbol"];
73+
self.state = [aDictionary valueForKey:@"state"];
74+
self.group = [aDictionary valueForKey:@"group"];
75+
self.period = [aDictionary valueForKey:@"period"];
76+
self.vertPos = [aDictionary valueForKey:@"vertPos"];
77+
self.horizPos = [aDictionary valueForKey:@"horizPos"];
78+
79+
}
80+
return self;
81+
}
82+
83+
- (void)dealloc {
84+
[atomicNumber release];
85+
[atomicWeight release];
86+
[discoveryYear release];
87+
[name release];
88+
[symbol release];
89+
[state release];
90+
[group release];
91+
[period release];
92+
[vertPos release];
93+
[horizPos release];
94+
[super dealloc];
95+
}
96+
97+
// this returns the position of the element in the classic periodic table locations
98+
-(CGPoint)positionForElement {
99+
return CGPointMake([[self horizPos] intValue] * 26-8,[[self vertPos] intValue]*26+35);
100+
101+
}
102+
103+
- (UIImage *)stateImageForAtomicElementTileView {
104+
return [UIImage imageNamed:[NSString stringWithFormat:@"%@_37.png",state]];
105+
}
106+
107+
108+
- (UIImage *)stateImageForAtomicElementView {
109+
return [UIImage imageNamed:[NSString stringWithFormat:@"%@_256.png",state]];
110+
}
111+
112+
- (UIImage *)stateImageForPeriodicTableView {
113+
return [UIImage imageNamed:[NSString stringWithFormat:@"%@_24.png",state]];
114+
}
115+
116+
117+
- (UIImage *)flipperImageForAtomicElementNavigationItem {
118+
119+
// return a 30 x 30 image that is a reduced version
120+
// of the AtomicElementTileView content
121+
// this is used to display the flipper button in the navigation bar
122+
CGSize itemSize=CGSizeMake(30.0,30.0);
123+
UIGraphicsBeginImageContext(itemSize);
124+
125+
UIImage *backgroundImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_30.png",state]];
126+
CGRect elementSymbolRectangle = CGRectMake(0,0, itemSize.width, itemSize.height);
127+
[backgroundImage drawInRect:elementSymbolRectangle];
128+
129+
// draw the element name
130+
[[UIColor whiteColor] set];
131+
132+
// draw the element number
133+
UIFont *font = [UIFont boldSystemFontOfSize:8];
134+
CGPoint point = CGPointMake(2,1);
135+
[[self.atomicNumber stringValue] drawAtPoint:point withFont:font];
136+
137+
// draw the element symbol
138+
font = [UIFont boldSystemFontOfSize:13];
139+
CGSize stringSize = [self.symbol sizeWithFont:font];
140+
point = CGPointMake((elementSymbolRectangle.size.width-stringSize.width)/2,10);
141+
142+
[self.symbol drawAtPoint:point withFont:font];
143+
144+
UIImage *theImage=UIGraphicsGetImageFromCurrentImageContext();
145+
UIGraphicsEndImageContext();
146+
return theImage;
147+
}
148+
149+
150+
151+
@end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
File: AtomicElementFlippedView.h
3+
Abstract: Displays the Atomic Element information with a link to Wikipedia.
4+
Version: 1.11
5+
6+
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
7+
Inc. ("Apple") in consideration of your agreement to the following
8+
terms, and your use, installation, modification or redistribution of
9+
this Apple software constitutes acceptance of these terms. If you do
10+
not agree with these terms, please do not use, install, modify or
11+
redistribute this Apple software.
12+
13+
In consideration of your agreement to abide by the following terms, and
14+
subject to these terms, Apple grants you a personal, non-exclusive
15+
license, under Apple's copyrights in this original Apple software (the
16+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
17+
Software, with or without modifications, in source and/or binary forms;
18+
provided that if you redistribute the Apple Software in its entirety and
19+
without modifications, you must retain this notice and the following
20+
text and disclaimers in all such redistributions of the Apple Software.
21+
Neither the name, trademarks, service marks or logos of Apple Inc. may
22+
be used to endorse or promote products derived from the Apple Software
23+
without specific prior written permission from Apple. Except as
24+
expressly stated in this notice, no other rights or licenses, express or
25+
implied, are granted by Apple herein, including but not limited to any
26+
patent rights that may be infringed by your derivative works or by other
27+
works in which the Apple Software may be incorporated.
28+
29+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
30+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34+
35+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42+
POSSIBILITY OF SUCH DAMAGE.
43+
44+
Copyright (C) 2010 Apple Inc. All Rights Reserved.
45+
46+
*/
47+
48+
#import <UIKit/UIKit.h>
49+
#import "AtomicElementView.h"
50+
51+
@interface AtomicElementFlippedView : AtomicElementView {
52+
UIButton *wikipediaButton;
53+
}
54+
55+
@property (nonatomic,retain) UIButton *wikipediaButton;
56+
57+
58+
@end

0 commit comments

Comments
 (0)