Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added duration customization. Added ARC support.

  • Loading branch information...
commit 8e454153a38d9a08af3c47de4c1ed9ba9435e574 1 parent 67e32bb
@Narmo Narmo authored
View
10 Classes/WToastAppDelegate.m
@@ -4,7 +4,7 @@
*/
#import "WToastAppDelegate.h"
-#import "WToastViewController.h"
+#import "WToastTestViewController.h"
@implementation WToastAppDelegate
@@ -14,10 +14,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
tabBarController = [[UITabBarController alloc] init];
- WToastViewController *v = [[WToastViewController alloc] init];
+ WToastTestViewController *v = [[WToastTestViewController alloc] initWithNibName:@"WToastTestViewController" bundle:nil];
v.tabBarItem.title = @"Test tab";
tabBarController.viewControllers = [NSArray arrayWithObject:v];
- [v release];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
@@ -42,10 +41,5 @@ - (void)applicationWillTerminate:(UIApplication *)application {
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
}
-- (void)dealloc {
- [window release];
- [tabBarController release];
- [super dealloc];
-}
@end
View
10 Classes/WToastTestViewController.h
@@ -0,0 +1,10 @@
+/**
+ * @class WToastTestViewController
+ * @author Nik S Dyonin <wolf.step@gmail.com>
+ */
+
+@interface WToastTestViewController : UIViewController <UITextFieldDelegate>
+
+@property (retain, nonatomic) IBOutlet UITextField *textField;
+
+@end
View
57 Classes/WToastTestViewController.m
@@ -0,0 +1,57 @@
+/**
+ * @class WToastTestViewController
+ * @author Nik S Dyonin <wolf.step@gmail.com>
+ */
+
+#import "WToastTestViewController.h"
+#import "WToast.h"
+
+@implementation WToastTestViewController
+
+@synthesize textField = _textField;
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.textField.delegate = self;
+}
+
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
+ [textField resignFirstResponder];
+ return NO;
+}
+
+- (IBAction)showShortMessage {
+ [self.textField resignFirstResponder];
+ NSString *text = self.textField.text;
+ if (!text || ![text length]) {
+ text = @"No text!";
+ }
+ [WToast showWithText:text];
+}
+
+- (IBAction)showLongMessage {
+ [self.textField resignFirstResponder];
+ NSString *text = self.textField.text;
+ if (!text || ![text length]) {
+ text = @"No text!";
+ }
+ [WToast showWithText:text length:kWTLong];
+}
+
+- (IBAction)showShortImage {
+ [WToast showWithImage:[UIImage imageNamed:@"test.png"]];
+}
+
+- (IBAction)showLongImage {
+ [WToast showWithImage:[UIImage imageNamed:@"test.png"] length:kWTLong];
+}
+
+- (void)dealloc {
+ self.textField = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
+ return YES;
+}
+
+@end
View
358 Classes/WToastTestViewController.xib
@@ -0,0 +1,358 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
+ <data>
+ <int key="IBDocument.SystemTarget">1296</int>
+ <string key="IBDocument.SystemVersion">11E53</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2182</string>
+ <string key="IBDocument.AppKitVersion">1138.47</string>
+ <string key="IBDocument.HIToolboxVersion">569.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">1181</string>
+ </object>
+ <array key="IBDocument.IntegratedClassDependencies">
+ <string>IBUIButton</string>
+ <string>IBUIView</string>
+ <string>IBUITextField</string>
+ <string>IBProxyObject</string>
+ </array>
+ <array key="IBDocument.PluginDependencies">
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </array>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0"/>
+ </object>
+ <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <object class="IBProxyObject" id="372490531">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="975951072">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIView" id="191373211">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">274</int>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="IBUITextField" id="85812643">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">293</int>
+ <string key="NSFrame">{{20, 20}, {280, 31}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="929239091"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <string key="IBUIText"/>
+ <int key="IBUIBorderStyle">3</int>
+ <string key="IBUIPlaceholder">Type message here</string>
+ <object class="NSColor" key="IBUITextColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ <object class="NSColorSpace" key="NSCustomColorSpace" id="1062276086">
+ <int key="NSID">2</int>
+ </object>
+ </object>
+ <bool key="IBUIAdjustsFontSizeToFit">YES</bool>
+ <float key="IBUIMinimumFontSize">17</float>
+ <object class="IBUITextInputTraits" key="IBUITextInputTraits">
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIFontDescription" key="IBUIFontDescription">
+ <int key="type">1</int>
+ <double key="pointSize">14</double>
+ </object>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica</string>
+ <double key="NSSize">14</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ </object>
+ <object class="IBUIButton" id="929239091">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">293</int>
+ <string key="NSFrame">{{67, 64}, {186, 37}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="1047793447"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentHorizontalAlignment">0</int>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <int key="IBUIButtonType">1</int>
+ <string key="IBUINormalTitle">Show short message</string>
+ <object class="NSColor" key="IBUIHighlightedTitleColor" id="1066811319">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <object class="NSColor" key="IBUINormalTitleShadowColor" id="993746344">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC41AA</bytes>
+ </object>
+ <object class="IBUIFontDescription" key="IBUIFontDescription" id="278947718">
+ <int key="type">2</int>
+ <double key="pointSize">15</double>
+ </object>
+ <object class="NSFont" key="IBUIFont" id="449476484">
+ <string key="NSName">Helvetica-Bold</string>
+ <double key="NSSize">15</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ </object>
+ <object class="IBUIButton" id="1047793447">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">293</int>
+ <string key="NSFrame">{{67, 109}, {186, 37}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="183056902"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentHorizontalAlignment">0</int>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <int key="IBUIButtonType">1</int>
+ <string key="IBUINormalTitle">Show long message</string>
+ <reference key="IBUIHighlightedTitleColor" ref="1066811319"/>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <reference key="IBUINormalTitleShadowColor" ref="993746344"/>
+ <reference key="IBUIFontDescription" ref="278947718"/>
+ <reference key="IBUIFont" ref="449476484"/>
+ </object>
+ <object class="IBUIButton" id="183056902">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">293</int>
+ <string key="NSFrame">{{67, 154}, {186, 37}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="399686425"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentHorizontalAlignment">0</int>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <int key="IBUIButtonType">1</int>
+ <string key="IBUINormalTitle">Show short image</string>
+ <reference key="IBUIHighlightedTitleColor" ref="1066811319"/>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <reference key="IBUINormalTitleShadowColor" ref="993746344"/>
+ <reference key="IBUIFontDescription" ref="278947718"/>
+ <reference key="IBUIFont" ref="449476484"/>
+ </object>
+ <object class="IBUIButton" id="399686425">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">293</int>
+ <string key="NSFrame">{{67, 199}, {186, 37}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentHorizontalAlignment">0</int>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <int key="IBUIButtonType">1</int>
+ <string key="IBUINormalTitle">Show long image</string>
+ <reference key="IBUIHighlightedTitleColor" ref="1066811319"/>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <reference key="IBUINormalTitleShadowColor" ref="993746344"/>
+ <reference key="IBUIFontDescription" ref="278947718"/>
+ <reference key="IBUIFont" ref="449476484"/>
+ </object>
+ </array>
+ <string key="NSFrame">{{0, 20}, {320, 460}}</string>
+ <reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="85812643"/>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ <reference key="NSCustomColorSpace" ref="1062276086"/>
+ </object>
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </array>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <array class="NSMutableArray" key="connectionRecords">
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">view</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="191373211"/>
+ </object>
+ <int key="connectionID">3</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">textField</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="85812643"/>
+ </object>
+ <int key="connectionID">9</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">showShortMessage</string>
+ <reference key="source" ref="929239091"/>
+ <reference key="destination" ref="372490531"/>
+ <int key="IBEventType">7</int>
+ </object>
+ <int key="connectionID">10</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">showLongMessage</string>
+ <reference key="source" ref="1047793447"/>
+ <reference key="destination" ref="372490531"/>
+ <int key="IBEventType">7</int>
+ </object>
+ <int key="connectionID">11</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">showShortImage</string>
+ <reference key="source" ref="183056902"/>
+ <reference key="destination" ref="372490531"/>
+ <int key="IBEventType">7</int>
+ </object>
+ <int key="connectionID">12</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">showLongImage</string>
+ <reference key="source" ref="399686425"/>
+ <reference key="destination" ref="372490531"/>
+ <int key="IBEventType">7</int>
+ </object>
+ <int key="connectionID">13</int>
+ </object>
+ </array>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <array key="orderedObjects">
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <array key="object" id="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">1</int>
+ <reference key="object" ref="191373211"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="85812643"/>
+ <reference ref="929239091"/>
+ <reference ref="1047793447"/>
+ <reference ref="183056902"/>
+ <reference ref="399686425"/>
+ </array>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="372490531"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="975951072"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">4</int>
+ <reference key="object" ref="85812643"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">5</int>
+ <reference key="object" ref="929239091"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6</int>
+ <reference key="object" ref="1047793447"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">7</int>
+ <reference key="object" ref="183056902"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">8</int>
+ <reference key="object" ref="399686425"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
+ </array>
+ </object>
+ <dictionary class="NSMutableDictionary" key="flattenedProperties">
+ <string key="-1.CustomClassName">WToastTestViewController</string>
+ <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="-2.CustomClassName">UIResponder</string>
+ <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
+ <nil key="activeLocalization"/>
+ <dictionary class="NSMutableDictionary" key="localizations"/>
+ <nil key="sourceID"/>
+ <int key="maxID">13</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">WToastTestViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <string key="NS.key.0">textField</string>
+ <string key="NS.object.0">UITextField</string>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <string key="NS.key.0">textField</string>
+ <object class="IBToOneOutletInfo" key="NS.object.0">
+ <string key="name">textField</string>
+ <string key="candidateClassName">UITextField</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/WToastTestViewController.h</string>
+ </object>
+ </object>
+ </array>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
+ <real value="1296" key="NS.object.0"/>
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <string key="IBCocoaTouchPluginVersion">1181</string>
+ </data>
+</archive>
View
12 Classes/WToastViewController.h
@@ -1,12 +0,0 @@
-/**
- * @class WToastViewController
- * @author Nik S Dyonin <wolf.step@gmail.com>
- */
-
-@interface WToastViewController : UIViewController <UITextFieldDelegate> {
- UITextField *textField;
- UIButton *showMessageButton;
- UIButton *showImageButton;
-}
-
-@end
View
100 Classes/WToastViewController.m
@@ -1,100 +0,0 @@
-/**
- * @class WToastViewController
- * @author Nik S Dyonin <wolf.step@gmail.com>
- */
-
-#import "WToastViewController.h"
-#import "WToast.h"
-
-@implementation WToastViewController
-
-- (void)redrawInterface:(UIInterfaceOrientation)orientation {
- CGRect screenFrame = [UIScreen mainScreen].bounds;
- float width, height;
- if (UIInterfaceOrientationIsLandscape(orientation)) {
- width = MAX(screenFrame.size.width, screenFrame.size.height);
- height = MIN(screenFrame.size.width, screenFrame.size.height);
- }
- else {
- width = MIN(screenFrame.size.width, screenFrame.size.height);
- height = MAX(screenFrame.size.width, screenFrame.size.height);
- }
-
- CGRect tmpRect = CGRectMake(0.0f, 30.0f, 300.0f, 40.0f);
- tmpRect.origin.x = floor((width - tmpRect.size.width) / 2.0f);
- textField.frame = tmpRect;
-
- tmpRect = showMessageButton.frame;
- tmpRect.origin.x = floor((width - tmpRect.size.width) / 2.0f);
- tmpRect.origin.y = textField.frame.origin.y + textField.frame.size.height + 20.0f;
- showMessageButton.frame = tmpRect;
-
- tmpRect = showImageButton.frame;
- tmpRect.origin.x = floor((width - tmpRect.size.width) / 2.0f);
- tmpRect.origin.y = showMessageButton.frame.origin.y + showMessageButton.frame.size.height + 30.0f;
- showImageButton.frame = tmpRect;
-}
-
-- (void)loadView {
- [super loadView];
-
- textField = [[UITextField alloc] init];
- textField.delegate = self;
- textField.borderStyle = UITextBorderStyleRoundedRect;
- textField.placeholder = @"Type message here";
- textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- textField.clearButtonMode = UITextFieldViewModeAlways;
- CGRect tmpRect = CGRectMake(0.0f, 30.0f, 300.0f, 40.0f);
- tmpRect.origin.x = floor((self.view.frame.size.width - tmpRect.size.width) / 2.0f);
- textField.frame = tmpRect;
- [self.view addSubview:textField];
- [textField release];
-
- showMessageButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [showMessageButton setTitle:@"Show message" forState:UIControlStateNormal];
- [showMessageButton sizeToFit];
- tmpRect = showMessageButton.frame;
- tmpRect.origin.x = floor((self.view.frame.size.width - tmpRect.size.width) / 2.0f);
- tmpRect.origin.y = textField.frame.origin.y + textField.frame.size.height + 20.0f;
- showMessageButton.frame = tmpRect;
- [self.view addSubview:showMessageButton];
- [showMessageButton addTarget:self action:@selector(showMessage:) forControlEvents:UIControlEventTouchUpInside];
-
- showImageButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [showImageButton setTitle:@"Show image" forState:UIControlStateNormal];
- [showImageButton sizeToFit];
- tmpRect = showImageButton.frame;
- tmpRect.origin.x = floor((self.view.frame.size.width - tmpRect.size.width) / 2.0f);
- tmpRect.origin.y = showMessageButton.frame.origin.y + showMessageButton.frame.size.height + 30.0f;
- showImageButton.frame = tmpRect;
- [self.view addSubview:showImageButton];
- [showImageButton addTarget:self action:@selector(showImage:) forControlEvents:UIControlEventTouchUpInside];
-}
-
-- (void)showMessage:(UIButton *)sender {
- [textField resignFirstResponder];
- NSString *text = textField.text;
- if (!text || ![text length]) {
- text = @"No text!";
- }
- [WToast showWithText:text];
-}
-
-- (void)showImage:(UIButton *)sender {
- [WToast showWithImage:[UIImage imageNamed:@"test.png"]];
-}
-
-- (BOOL)textFieldShouldReturn:(UITextField *)aTextField {
- [aTextField resignFirstResponder];
- return NO;
-}
-
-- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- [self redrawInterface:toInterfaceOrientation];
-}
-
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
- return YES;
-}
-
-@end
View
22 WToast.xcodeproj/project.pbxproj 100755 → 100644
@@ -11,7 +11,8 @@
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
- AF5198C8142BBC41003E97EE /* WToastViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AF5198C7142BBC41003E97EE /* WToastViewController.m */; };
+ AF1AA29415A305A500C87E9E /* WToastTestViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AF1AA29215A305A500C87E9E /* WToastTestViewController.m */; };
+ AF1AA29515A305A500C87E9E /* WToastTestViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = AF1AA29315A305A500C87E9E /* WToastTestViewController.xib */; };
AF53D3C5134F4EAB00519C3A /* WToast.m in Sources */ = {isa = PBXBuildFile; fileRef = AF53D3C4134F4EAB00519C3A /* WToast.m */; };
AF53D486134F5CE200519C3A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF53D485134F5CE200519C3A /* QuartzCore.framework */; };
AF53D4A1134F5CF100519C3A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF53D4A0134F5CF100519C3A /* CoreGraphics.framework */; };
@@ -27,8 +28,9 @@
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* WToast_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WToast_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* WToast-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "WToast-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
- AF5198C6142BBC41003E97EE /* WToastViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WToastViewController.h; sourceTree = "<group>"; };
- AF5198C7142BBC41003E97EE /* WToastViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WToastViewController.m; sourceTree = "<group>"; };
+ AF1AA29115A305A500C87E9E /* WToastTestViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WToastTestViewController.h; sourceTree = "<group>"; };
+ AF1AA29215A305A500C87E9E /* WToastTestViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WToastTestViewController.m; sourceTree = "<group>"; };
+ AF1AA29315A305A500C87E9E /* WToastTestViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WToastTestViewController.xib; sourceTree = "<group>"; };
AF53D3C3134F4EAB00519C3A /* WToast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WToast.h; sourceTree = "<group>"; };
AF53D3C4134F4EAB00519C3A /* WToast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WToast.m; sourceTree = "<group>"; };
AF53D485134F5CE200519C3A /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
@@ -56,8 +58,9 @@
children = (
1D3623240D0F684500981E51 /* WToastAppDelegate.h */,
1D3623250D0F684500981E51 /* WToastAppDelegate.m */,
- AF5198C6142BBC41003E97EE /* WToastViewController.h */,
- AF5198C7142BBC41003E97EE /* WToastViewController.m */,
+ AF1AA29115A305A500C87E9E /* WToastTestViewController.h */,
+ AF1AA29215A305A500C87E9E /* WToastTestViewController.m */,
+ AF1AA29315A305A500C87E9E /* WToastTestViewController.xib */,
);
path = Classes;
sourceTree = "<group>";
@@ -174,6 +177,7 @@
buildActionMask = 2147483647;
files = (
AFA2273E1361D9BD005139AD /* test.png in Resources */,
+ AF1AA29515A305A500C87E9E /* WToastTestViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -187,7 +191,7 @@
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* WToastAppDelegate.m in Sources */,
AF53D3C5134F4EAB00519C3A /* WToast.m in Sources */,
- AF5198C8142BBC41003E97EE /* WToastViewController.m in Sources */,
+ AF1AA29415A305A500C87E9E /* WToastTestViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -198,11 +202,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = WToast_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "WToast-Info.plist";
PRODUCT_NAME = WToast;
};
@@ -212,9 +218,11 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = WToast_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "WToast-Info.plist";
PRODUCT_NAME = WToast;
VALIDATE_PRODUCT = YES;
@@ -225,6 +233,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
@@ -240,6 +249,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
View
8 WToast/WToast.h
@@ -5,9 +5,17 @@
#define RGB(a, b, c) [UIColor colorWithRed:(a / 255.0f) green:(b / 255.0f) blue:(c / 255.0f) alpha:1.0f]
#define RGBA(a, b, c, d) [UIColor colorWithRed:(a / 255.0f) green:(b / 255.0f) blue:(c / 255.0f) alpha:d]
+typedef enum {
+ kWTShort = 1,
+ kWTLong = 5
+} WToastLength;
+
@interface WToast : UIView
+ (void)showWithText:(NSString *)text;
+ (void)showWithImage:(UIImage *)image;
++ (void)showWithText:(NSString *)text length:(WToastLength)length;
++ (void)showWithImage:(UIImage *)image length:(WToastLength)length;
+
@end
View
50 WToast/WToast.m
@@ -9,15 +9,31 @@
#define TABBAR_OFFSET 44.0f
+@interface WToast()
+
+@property (nonatomic) NSInteger length;
+
+@end
+
+
@implementation WToast
+@synthesize length = _length;
+
+- (id)initWithFrame:(CGRect)frame {
+ if ((self = [super initWithFrame:frame]) != nil) {
+ _length = kWTShort;
+ }
+ return self;
+}
+
- (void)__show {
[UIView animateWithDuration:0.2f
animations:^{
self.alpha = 1.0f;
}
completion:^(BOOL finished) {
- [self performSelector:@selector(__hide) withObject:nil afterDelay:1];
+ [self performSelector:@selector(__hide) withObject:nil afterDelay:_length];
}];
}
@@ -27,7 +43,11 @@ - (void)__hide {
self.alpha = 0.0f;
}
completion:^(BOOL finished) {
- [self removeFromSuperview], [self release];
+ [self removeFromSuperview];
+#if !__has_feature(objc_arc)
+ [self release];
+#endif
+
}];
}
@@ -89,7 +109,9 @@ + (WToast *)__createWithText:(NSString *)text {
tmpRect.size = sz;
textLabel.frame = tmpRect;
[toast addSubview:textLabel];
+#if !__has_feature(objc_arc)
[textLabel release];
+#endif
toast.alpha = 0.0f;
@@ -145,7 +167,9 @@ + (WToast *)__createWithImage:(UIImage *)image {
tmpRect.size = sz;
imageView.frame = tmpRect;
[toast addSubview:imageView];
+#if !__has_feature(objc_arc)
[imageView release];
+#endif
toast.alpha = 0.0f;
@@ -206,7 +230,25 @@ - (void)__flipViewAccordingToStatusBarOrientation {
* @param text Text to print in toast window
*/
+ (void)showWithText:(NSString *)text {
+ [WToast showWithText:text length:kWTShort];
+}
+
+/**
+ * Show toast with image in application window
+ * @param image Image to show in toast window
+ */
++ (void)showWithImage:(UIImage *)image {
+ [WToast showWithImage:image length:kWTShort];
+}
+
+/**
+ * Show toast with text in application window
+ * @param text Text to print in toast window
+ * @param length Toast visibility duration
+ */
++ (void)showWithText:(NSString *)text length:(WToastLength)length {
WToast *toast = [WToast __createWithText:text];
+ toast.length = length;
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview:toast];
@@ -218,9 +260,11 @@ + (void)showWithText:(NSString *)text {
/**
* Show toast with image in application window
* @param image Image to show in toast window
+ * @param length Toast visibility duration
*/
-+ (void)showWithImage:(UIImage *)image {
++ (void)showWithImage:(UIImage *)image length:(WToastLength)length {
WToast *toast = [WToast __createWithImage:image];
+ toast.length = length;
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview:toast];
View
8 main.m
@@ -1,8 +1,8 @@
#import "WToastAppDelegate.h"
int main(int argc, char *argv[]) {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([WToastAppDelegate class]));
- [pool release];
- return retVal;
+ @autoreleasepool {
+ int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([WToastAppDelegate class]));
+ return retVal;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.