Search This Blog

Wednesday 20 March 2013

Toast Message iOS

Hi,
I am going to show you here how to use Toast message and disappear it automatically after some interval.Many users do not want to use UIAlertView because it needs to close manually.Toast shows the message on the screen for the time we specified and will dismiss automatically after time is up.I have not customized the Toast but i am using some files to show the message in Toast.

Steps :
1. Download two files Toast+UIView.h & Toast+UIView.m from here  and add those in project.
2.Link against QuartzCore.
If you are using ARC,then you will need to add the    -fno-objc-arc compiler flag to  Toast+UIView.m.

3.Now in your project,import the files and use the code as per your specifications,


// basic usage
[self.view makeToast:@"This is a piece of toast."];

// toast with duration, title, and position
[self.view makeToast:@"This is a piece of toast with a title." 
             duration:3.0
             position:@"top"
                title:@"Toast Title"];

// toast with an image
[self.view makeToast:@"This is a piece of toast with an image." 
            duration:3.0
            position:[NSValue valueWithCGPoint:CGPointMake(110, 110)]
               image:[UIImage imageNamed:@"toast.png"]];

// display toast with an activity spinner
[self.view makeToastActivity];

Thats it.We are done.
If you face any issue then please comment.
Happy Coding...!

Thursday 7 March 2013

NSUserDefaults iOS

Hi ,


In this tutorial, I will be showing you how you can save and retrieve different types of data using the NSUserDefaults object. Saving this way is great for when you want to save small amounts of data such as High Scores, Login Information, and program state.

With the NSUserDefaults class, you can save settings and properties related to application or user data. For example, you could save a profile image set by the user or a default color scheme for the application. The objects will be saved in what is known as the iOS “defaults system”. The iOS defaults system is available throughout all of the code in your app, and any data saved to the defaults system will persist through application sessions. This means that even if the user closes your application or reboots their phone, the saved data will still be available the next time they open the app!

Saving to the NSUserDefaults is great because it does not require any special database knowledge. So if you don’t want/have an SQLite3 database for your app, this would be the way to go.



How to store/save data in NSUserDefaults :



NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// store a NSString
[userDefaults setObject:@"TextToSave" forKey:@"keyToLookupString"];
// store an NSInteger
[userDefaults setInteger:42 forKey:@"integerKey"];
// store a Double
[userDefaults setDouble:3.1415 forKey:@"doubleKey"];
// store a Float
[userDefaults setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch userDefaults
[userDefaults synchronize];
Your stored now.You can retrive it whenever you need.



To Retrieve stored data from NSUserDefaults :

NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [userDefaults stringForKey:@"
keyToLookupString"];
// getting an NSInteger
NSInteger myInt = [userDefaults integerForKey:@"
integerKey"];
// getting an Float
float myFloat = [userDefaults floatForKey:@"
floatKey"];
You just retrieved the values stored.
If you have any questions or comments, feel free to leave them in the comments section of this post. Happy iCoding!