Tuesday 27 August 2013

Check the text Font is "Bold" or "Italic" UIFont.



Import CoreTextFrameWork.

#import <CoreText/CoreText.h>


+(BOOL)isBold
{
    CTFontRef fontRef = (__bridge CTFontRef)self;
    CTFontSymbolicTraits symbolicTraits = CTFontGetSymbolicTraits(fontRef);
    return (symbolicTraits & kCTFontBoldTrait);
}

+(BOOL)isItalic
{
    CTFontRef fontRef = (__bridge CTFontRef)self;
    CTFontSymbolicTraits symbolicTraits = CTFontGetSymbolicTraits(fontRef);
    return (symbolicTraits & kCTFontItalicTrait);
}

Friday 23 August 2013

Git Hub Tutorial. Introduction to commands.

Introduction: 
When working on a project, you need to manage and organize the code. 
Like organize according to User modified a file in the project, or Date and time when you changed the file and many other.
Git keep the track of the files you changed and also allow you to update the code on remote device,and allow your team mates to access the code. Now, they can access the modify code and all other files in more organized way. 
Difference:
The major difference between Git and any other VCS (Subversion and friends included) is the way Git thinks about its data. Conceptually, most other systems store information as a list of file-based changes. These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as a set of files and the changes made to each file over time.

Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like "SAVED STATE", a set of snapshots of a mini filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
For Example if a major Bug occurs after the changes then you can go back to a "saved state", start building again from there. Like that you paused a game to a state and then can resume from that point.
To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored.
      pull 
  <---------------------
    User                                        Remote Repository        
      -----------------------> 
                     push

pull    -   Fetch data from Remote Repository.
push  -   Update the Remote Repository with local changes.


USER 1 USER2
        \ \         / /
          \  \     / /
       Remote Repository        
            / /     \ \                                            
              / /           \ \
        USER n USER3






There are two easy ways to install Git on a Mac. The easiest is to use the graphical Git installer, which you can download from the Google Code page 
http://code.google.com/p/git-osx-installer
The other major way is to install Git via MacPorts (http://www.macports.org). 
If you have MacPorts installed, install Git via
$ sudo port install git-core +svn +doc +bash_completion +gitweb
You don’t have to add all the extras, but you’ll probably want to include +svn in case you ever have to use Git with Subversion repositories



Lets Begin:
Press "cmd" + space"
Type : "terminal" in spotlight.
It will open a terminal window. 

Browse to folder where you want to store the project locally. You can "cd" command to navigate in in your folders.
cd Users/HD/Desktop/Git/
It will take to the folder Git.

You clone a repository with git clone [url]. For example, if you want to clone the Ruby Git library called Grit, you can do so like this:
$ git clone git://github.com/HD/grit.git


The main tool you use to determine which files are in which state is the git status command. If you run this command directly after a clone, you should see something like this:
$ git status


In order to begin tracking a new file, you use the command git add. To begin tracking the READMEfile, you can run this:
$ git add README

Now that your staging area is set up the way you want it, you can commit your changes. Remember that anything that is still unstaged — any files you have created or modified that you haven’t rungit add on since you edited them — won’t go into this commit. They will stay as modified files on your disk. In this case, the last time you ran git status, you saw that everything was staged, so you’re ready to commit your changes. The simplest way to commit is to type git commit:
You can type your commit message inline with the commit command by specifying it after a -m flag, like this:
$ git commit -m "Eg: This is custom msg related to commit"




Pushing Remotely
The push command tells Git where to put our commits when we're ready, and boy we're ready. So let's push our local changes to our origin repo (on GitHub).
The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it! 
$ git push -u origin master





eBook:
Tuts:

Monday 12 August 2013

Show Hide the side content view with UIButton click.


We need to display a help menu or content of book which scrolls up on the view and show new view to the user.

Declare a BOOL to check view is hidden or not.
In .h
BOOL _isContentVisible
UIView *_sideContentView;
-(IBAction)showHideContentView:(id)sender;
In .Xib
Connect the showHideContentView function to UIButton touchUpInside action.
In .m
-(void)showHideContentView:(id)sender
{
    //BOOL isContentVisible= CGRectIntersectsRect(self.view.bounds, _sideContentScrollView.frame); // you can check view visibility if its scrollview.

    [UIView animateWithDuration:1.0f
                          delay:0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         //hide if visible else show

                         if (_isContentVisible) { // Hide
                             _isContentVisible = NO;
                             [_sideContentView setFrame:CGRectMake(-360 +40, 0, 360, 748)];// 40 pixels is button to be seen on the view. Set the frame according to your choice.

                         }
                         else { // Show
                             _isContentVisible = YES;
                             [_sideContentView setFrame:CGRectMake(0, 0, 360, 748)];
                         }
                     }
                     completion:^(BOOL finished) {
                         if (finished) {
                          // Do any custom stuff on completion.
                         }
                     }];
}

Tuesday 6 August 2013

Check that string contains only numeric values (number 0-9).


+(BOOL) validateStringContainsNumbersOnly:(NSString*)strng
{
    NSCharacterSet *s = [NSCharacterSet characterSetWithCharactersInString:@"1234567890"];

    s = [s invertedSet];
    //And you can then use a string method to find if your string contains anything in the inverted set:

    NSRange r = [strng rangeOfCharacterFromSet:s];
    if (r.location != NSNotFound) {
        NSLog(@"the string contains illegal characters");
        return NO;
    }
    else
        return YES;
}

Check if string contains only alphabets. Using NSString, NSCharacterSet, NSRange.


+(BOOL) validateStringContainsAlphabetsOnly:(NSString*)strng
{
    NSCharacterSet *strCharSet = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];//1234567890_"];

    strCharSet = [strCharSet invertedSet];
    //And you can then use a string method to find if your string contains anything in the inverted set:

        NSRange r = [strng rangeOfCharacterFromSet:strCharSet];
    if (r.location != NSNotFound) {
        NSLog(@"the string contains illegal characters");
        return NO;
    }
    else
        return YES;
}

Sunday 4 August 2013

Find number of days between two dates.


+ (int)daysBetweenFromDate:(NSDate*)fromDateTime toDate:(NSDate*)toDateTime
{
    NSDate *fromDate;
    NSDate *toDate;

    //initialize the calender
    NSCalendar *calendar = [NSCalendar currentCalendar];

    //Returns by reference the starting time and duration of a given calendar unit that contains a given date.
    [calendar rangeOfUnit:NSDayCalendarUnit startDate:&fromDate
                 interval:NULL forDate:fromDateTime];
    
    [calendar rangeOfUnit:NSDayCalendarUnit startDate:&toDate
                 interval:NULL forDate:toDateTime];

    //Returns, as an NSDateComponents object using specified components, the difference between two supplied dates.
    NSDateComponents *difference = [calendar components:NSDayCalendarUnit
                                               fromDate:fromDate toDate:toDate options:0];
    
    return [difference day];
}