Tuesday 31 December 2013

GridView in iOS.

As you guys have collection view , you can use it as grid.
Then you think what I have made to use for?

So, I am presenting advantage of my GridView below:--

1)First of all it is compatible with ios 5.0 + , on the other hand , UICollectionView doen't work in iOS 5.0.
2)It automatically adjust cell blocks according to string size and extend width of the grid.
3)It allows you to define cell type as if you want to give input or keep it as simple label.
4)Also allows to perform calculation like
    Add,
    Multiply
    Subtract
    Devide
    and Mod Operation on cell.
5)Row click action returns row data in the format of NSDictionary.
6)Support landscape as well as portrait mode.
7)Made for both iPhone and iPad.




1) First of all you need to download library I have put on the shared link

Download GridViewLib Here

2) After you have downloaded it,Import both "include" and "libGridViewTable.a" to your project and check copy to folder option while adding.After importing it would look like image below.
  


3)Don't forget to add some framework:
     i)QuartzCore Framework
     ii)CoreGraphics Framework


4) Go to Project->Build Setting -> Search Header Path
    and set path to $SOURCE_ROOT/include
    and "Always Search User Paths" to YES as shown below



5) Now you have successfully added the library , you can use it by just importing "GridViewTable.h" file and use its DataSource and Delegate Methods.

Here is demo how I have used in header and Implementation File.





Monday 30 December 2013

How to add methods to existing protocol?

Sometimes we need to enable touchBegans on UITableView instead of didSelect method but
we are not able to do it.

So here we make a custom protocols methods to invoke touchesBegan and touchesEnded methods using Category files.

Follow the steps to do so:-

1)Within your project , Go to File Menu ->File -> New and click.
2)It will show dialog having two segments that is IOS and OS X . Withing IOS , select Cocoa Touch.
3)After that , click on "Objective-C category" option and go next.



4)It'll display another dialog having two options with Input Fields that is "Category" and "Category On".
5)Give TouchGesture as Category and select UITableView in Category On option and go next and click create button.
6)It will create two Files named UITableView+TouchGesture.h and UITableView+TouchGesture.m



Now  we have created category files successfully, and further we will work on custom protocols to UITableView delegate.

In header File , create a protocol named MyCustomDelegate subclass of UITableViewDelegate and write two methods within it like given below:-

@protocol MyCustomDelegate <UITableViewDelegate>
-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event;
-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end


and Within Interface write a method to invoke custom delegate like

- (id<MyCustomDelegate>) customDelegate;

Now your header file would look like




In Implementation File , define interface method and call delegates on touchBegan and touchEnded gesture methods as given in the file.



At last we made it , now you can use it by importing UITableView+TouchGesture.h file in the place wherever you want to use this new delegate method that will invoke on the touchBegan and touchEnded of tableView.But keep in mind by implementing these methods didSelect method will not work.

write this tableView protocol in your viewController and perform your task within it.

-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
  //do your stuff.
}

-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 //do your stuff.
}

Friday 2 August 2013

Storage File


           As u have used NSUserDefaults to store values of type whatever you want to choose from the List of Valid Object to set for a specified Key.
 Like if you want to set NSDictionary Object to NSUserDefaults then you use code like this  [[NSUserDefaults standardUserDefaults] setObject:dictionaryObject forKey:@"myDictionary"];
 Similarly Storage File will work for you.

 You Just need to use this file like

 [[SharedManager sharedManager] setObject:dictionaryObject forKey:@"myDictionary"];

 How it works--

 It has one static instance of storage file that it returns when you call [SharedManager sharedManager].
 As it is static instance, Any change to this file will reflect in all the class in which you are using it.And change from anywhere to this class will update it to be used in another class.

 It has its own plist file that keep your value persist when application closed.And return it to you whenever you call it again after launching application next time.

 Plus point is that you can also store CGRect and CGSize to this file.

SharedManager.h File

SharedManager.m File

---------------------

I have used this file as you can see below how to set data to it.


    SharedManager *sm=[SharedManager sharedManager];
   
    NSArray *myArray=[[NSArray alloc] initWithObjects:@"Rohan",@"Folks",@"Alien",@"Animals",@"Karizma",nil];
   
    NSDictionary *myDictionary=[[NSDictionary alloc] initWithObjectsAndKeys:@"Banana",@"Fruit",@"Zebra",@"Animal",@"Parrot",@"Birds",nil];
   
    NSString *myString=@"I am String";
   
    NSData *data=[myString dataUsingEncoding:NSUTF8StringEncoding];
   
    CGRect rect=CGRectMake(97, 443, 200, 450);
   
    CGSize size=CGSizeMake(340, 564);
   
    [sm setSize:size ForKey:@"mysize"];
    [sm setRect:rect ForKey:@"myrect"];
    [sm setData:data ForKey:@"mydata"];
    [sm setBool:YES ForKey:@"mybool"];
    [sm setObject:myString ForKey:@"myStr"];
    [sm setObject:myArray ForKey:@"myarray"];
    [sm setObject:myDictionary ForKey:@"mydict"];


And here is reference code to use this for getting info's you have set.

    SharedManager *sm=[SharedManager sharedManager];
   
    NSLog(@"my size string is %@",NSStringFromCGSize([sm sizeForKey:@"mysize"]));
    NSLog(@"my rectangle is %@",NSStringFromCGRect([sm rectForKey:@"myrect"]));
    NSLog(@"my data to string is %@", [[NSString alloc] initWithData:[sm dataForKey:@"mydata"] encoding:NSUTF8StringEncoding]);
    NSLog(@"my bool is %i",[sm boolForKey:@"mybool"]);
    NSLog(@"my array is %@",[sm ObjectForKey:@"myarray"]);
    NSLog(@"my dict is %@",[sm ObjectForKey:@"mydict"]);
    NSLog(@"my string is %@",[sm ObjectForKey:@"myStr"]);

Tuesday 23 July 2013

Setting gradient colors to UISlider bar.

You can make your slider more beautiful by applying custom gradient colors to it.Have  a look at following tricks we can use to colorful our UISlider object.

Import QuartzCore Framework.

Create an instance of UISlider and pass it with array of colors to set in to slider bar only after it has been instantiated successfully.

Gradient Set method is displaying below:----


Now Let us see what we have done in this method.

0)Get min_trackImageView and max_trackImageView object from subviews of UISlider object.
1)Create gradient Layers for min_trackImage and max_trackImage respectively.
2)Set layers frame to slider min_trackImage frame and max_trackImage properly along with changing x position of gradient layer.
3)Set its startPoint to Left and endPoint to right.
4)Using QuartzCore concept we set layers corner radius to 5.0;
5)Assign color array to gradient Layer and insert as subLayer to min_trackImageView and _max_trackImageView at index 0;

How to use it:-

Using this method is very simple . Just call this method with slider object and color array as parameter after UISlider Object has instanciated otherwise you will not see code reflection to your device or simulator.

Here is a piece of code displaying how to use it.---




And here is your output.