Search This Blog

Monday 15 July 2013

Customising and using UIFonts

Hi Friends,

I am going to explain you how to add and use customised UIFonts in our app.

When you have UIFont files such as .otf etc. you can simply use it in your code.

Lets start with following steps,

1.Add all UIFont files (.otf etc) in project bundle (drag and drop in project) and select copy and add to Target.It will show the fonts in project.

2.Go to .plist file of your project and create Array new entry as 'Fonts provided by application'.

3.Add key in that item 0,item 1,etc. based on your number of fonts you want to use and their values should be the names of Font files.for eg. Value of item 0 can be 'MyriadPro-Regular.otf' etc.Here, 'MyriadPro-Bold' is the name of font.

We are done with it.Now we need to use this fonts.Its the normal way you are setting UIFonts.

If I want to set the custom font to tableView cell then I write,


            cell.textLabel.font = [UIFont fontWithName:@"MyriadPro-Regular" size:20];

In this way you can simply use this fonts in your code.

Feel free to comment.

Happy coding :)





Tuesday 11 June 2013

New Features Of iOS 7

Hi,
Apple just changed the operating system for the iPhone and iPad in a big way. On Monday at its World Wide Developers Conference, Apple unveiled iOS 7, a redesigned version of the software that runs its mobile devices. It is almost everything that we expected from Apple… and a little bit more.
Apple has several primary new features in iOS 7 to go along with a new design from its top developer, Jony Ive. The new iOS is sleeker and has gone “flat,” eschewing shadows and real-life objects (like notebooks and bookshelves) to give the operating system a more modern look, which is a big departure from how Apple has presented iOS in the past. 

Outside the simplified design, here are the biggest new features to in iOS 7:

Multi-tasking: Apple has brought multi-tasking to every single app, not just a select few. The new multi-tasking features will allow apps to interact with the operating system and sometimes other apps. A new multi-tasking application programming interface (API) will allow all apps to run in the background and allow users to switch between apps. iOS 7 will know what apps that consumers use most and keep those running in the background.



Control Center: The new settings menu for iOS that will control features such as Wi-Fi, Bluetooth, mute, screen brightness and so forth. If you are familiar with Google’s Android operating system, the iOS 7 Control Center will seem quite familiar, but instead of accessing the settings by dragging from the top of the smartphone screen, users in iOS 7drag from the bottom. 


Notification Center: The drop-down notification center is now available from the lock screen on your iOS device and will provide you with details of your day, such as calendar appointments or weather updates. 



AirDrop: This is a new content sharing feature that works wirelessly. AirDrop allows you to share content with your contacts that are close to you. Select who you want to share with, select what you want to share and AirDrop will send that content to the person. By doing it through Wi-Fi or cellular data, Apple has essentially said that Near Field Communications (NFC, a technology that allows sharing with a “tap”) is not coming to the new iPhone later this year.


Camera features: Apple has long been known to push the camera functionality of its iPhones. We will likely see more of what Apple has up its sleeve with its camera when the new iPhone is announced later this year. But iOS 7 gives us a sneak peek. Apple thinks it is four cameras in one as it has several different settings like a “square mode.” The other three modes of the camera are video, normal photos and panorama. Users will be able to flip between the different modes with a swipe.



Photo gallery: More than any other new feature in iOS 7, the photo gallery benefits from Apple’s personal cloud product, iCloud. The Photos app features the iCloud Photo Stream that aggregates all of your pictures through the years into one long timeline. The iCloud Photo Stream will allow users to easily share photos with other iCloud users.



Safari: Apple could not update its mobile operating system without giving its browser a big update. Mobile Safari should be faster, have simplified search and a new browser tab interface that is based on rotating tiles. It will also save your passwords with the iCloud Keychain and has enhanced parental controls.



Siri: Apple’s virtual assistant got a little bit better. Siri now hooks straight to Twitter, Wikipedia and Microsoft’s Bing search engine. Users will also be able to control device features straight from Siri, such as turning on Wi-Fi or adjusting screen brightness. Siri will also have male and female voices as well as being available in several new languages. Siri will also have new features for automobiles.

iTunes Radio: The worst-kept secret before the WWDC keynote was the fact that Apple was coming out with a streaming radio music player. The rumors were not quite right in calling it iRadio though, as the new music app’s streaming capabilities are called iTunes Radio. It is similar to Pandora or Spotify’s radio app and has distinct similarities to Google’s Play All Access music service. iTunes Radio is meant for music discovery and will be free to users. If you are an iTunes subscriber, it will be served without advertisements.



Auto Updates For Apps: No longer will your iOS device has a long backlog of apps that you have not gotten around to updating. Apple will now update those apps automatically for you. 
Apple also has a slew of secondary features in iOS 7 such as an “Activation Lock” for the “Find My iPhone” feature that integrates your iCloud Apple ID password to thwart people from stealing your phone and accessing your information. Night Mode responds to ambient light and adjusts the brightness of the screen to help you see. 


Apple has nearly 1,500 new software developer kit (SDK) features for developers to access within iOS 7. That is a fairly considerable update. Developers will have access to iOS 7 beta today and users will see it this fall when Apple releases the next iPhone. 

Thursday 30 May 2013

Customize Grid view with Images iOS

Hi,

I am going to explain you here how to create Grid view of image view and buttons that allows us to select any images,mark selected and recognize which image was selected.I am using NOT using UITableView,just using UIImageViews and UIButtons to create Grid.

Here is the grid you will see before you select any image :


Next,the grid you will see after you select any images :

Lets start,

1.Create a master details navigation project or any project.I used storyboard in sample.
2.Drag and drop any images into your project to present those in grid.

 We are creating grid with uiimages and uibuttons programmatically adding it onto the uiview setting x,y coordinates.We are adding scroll view as because we may have thousands of images to display.

3.Go to DetailViewController.h, where you want to create grid and add following,

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
{
    UIScrollView *myScrollView;
    UIImageView *image;
NSMutableArray *arr_Images;
    NSMutableArray *arr_isImagesChecked;

UIButton *btn_imageBackground;

}
@property (strong, nonatomic) id detailItem;
@property (nonatomic,retain) UIScrollView *myScrollView;
@property (nonatomic,retain) UIImageView *image;
@property (nonatomic,retain) UIButton *btn_imageBackground;

@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

- (IBAction)btnImageClicked:(id)sender;

@end 

Here we are declaring controls.

4.Open DetailViewController.m and add,


#import "DetailViewController.h"

@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation DetailViewController
@synthesize myScrollView;
@synthesize image;
@synthesize btn_imageBackground;

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;
        
        // Update the view.
        [self configureView];
    }

    if (self.masterPopoverController != nil) {
        [self.masterPopoverController dismissPopoverAnimated:YES];
    }        
}

- (void)configureView
{
    // Update the user interface for the detail item.
       self.myScrollView.backgroundColor=[UIColor blackColor];
        int x=10,y=10;
        
        for (int i=0; i<[arr_Images count]; i++) {
            //NSLog(@"IN FOR index i = %d",i);
            //NSLog(@"Array count %d",[arr_Images count]-1);
            
            if (x > 300) {
                x=10;
                y=y+50;

                image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:[arr_Images objectAtIndex:i]]];
                image.frame=CGRectMake(x, y, 45, 45);
                
                               
                btn_imageBackground=[UIButton buttonWithType:UIButtonTypeCustom] ;
                btn_imageBackground.frame=CGRectMake(x, y, 45, 45);
                [btn_imageBackground addTarget:self action:@selector(btnImageClicked:) forControlEvents:UIControlEventTouchUpInside];
                x=x+50;
            }
            else {
                
                image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:[arr_Images objectAtIndex:i]]];
                image.frame=CGRectMake(x, y, 45, 45);
                
                               
                btn_imageBackground=[UIButton buttonWithType:UIButtonTypeCustom] ;
                btn_imageBackground.frame=CGRectMake(x, y, 45, 45);
                [btn_imageBackground addTarget:self action:@selector(btnImageClicked:) forControlEvents:UIControlEventTouchUpInside];
                x=x+50;
                
            }
            image.tag=i;
            btn_imageBackground.tag=i;
            
            [self.myScrollView addSubview:image];
            [self.myScrollView addSubview:btn_imageBackground];
            [self.view addSubview:myScrollView];
            
        }
    

}
- (IBAction)btnImageClicked:(id)sender
{

    if ([[arr_isImagesChecked objectAtIndex:[sender tag]] intValue]) {
        //image selected so deselect it
        [sender setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [arr_isImagesChecked replaceObjectAtIndex:[sender tag] withObject:[NSNumber numberWithUnsignedInteger:0]];
    }else{
    //image not selected so select it by adding checked image onto the UIbutton
        [sender setImage:[UIImage imageNamed:@"Overlay.png"] forState:UIControlStateNormal];
        [arr_isImagesChecked replaceObjectAtIndex:[sender tag] withObject:[NSNumber numberWithUnsignedInteger:1]];
        NSLog(@"%@",arr_isImagesChecked );
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

//Initialize array of images with images
        arr_Images =[[NSMutableArray alloc]initWithObjects:@"images-1.jpeg",@"images-2.jpeg",@"images-3.jpeg",@"images-4.jpeg",@"images1.jpg",@"images2.jpg",@"images3.jpg",@"images4.jpg",@"images-1.jpeg",@"images-2.jpeg",@"images-3.jpeg",@"images-4.jpeg",@"images1.jpg",@"images2.jpg",@"images3.jpg",@"images4.jpg",@"images-1.jpeg",@"images-2.jpeg",@"images-3.jpeg",@"images-4.jpeg",@"images1.jpg",@"images2.jpg",@"images3.jpg",@"images4.jpg",nil];
    arr_isImagesChecked = [[NSMutableArray alloc] init];
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    myScrollView = [[UIScrollView alloc]   initWithFrame:CGRectMake(0, 0, 320, screenBounds.size.height)];
myScrollView.contentSize = CGSizeMake(1, [arr_Images count]*10);

// Initialize array of flag to 0
    for (int i=0; i<[arr_Images count]; i++) {
        [arr_isImagesChecked insertObject:[NSNumber numberWithUnsignedInteger:0] atIndex:i];
    }

    [self configureView];  
}

@end


that's it.Just run the code you will get the output.You can download the code from here.
If you need help,feel free to comment.Happy coding :)

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!