Limiting Zoom level in UIPinchGestureRecognizer

Sometimes when we are zooming image by using Pinch Gesture, we can’t handle the size of zooming. Here is a small code to do this.

The code below assumes there is an instance variable CGFloat lastScale and that a view has been set for the UIPinchGestureRecognizer.

– (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {

if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
// Reset the last scale, necessary if there are multiple objects with different scales
lastScale = [gestureRecognizer scale];
}

if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
[gestureRecognizer state] == UIGestureRecognizerStateChanged) {

CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@”transform.scale”] floatValue];

// Constants to adjust the max/min values of zoom
const CGFloat kMaxScale = 2.0;
const CGFloat kMinScale = 1.0;

CGFloat newScale = 1 –  (lastScale – [gestureRecognizer scale]); // new scale is in the range (0-1)
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
CGAffineTransform transform = CGAffineTransformScale([[gestureRecognizer view] transform], newScale, newScale);
[gestureRecognizer view].transform = transform;

lastScale = [gestureRecognizer scale];  // Store the previous scale factor for the next pinch gesture call
}
}

!! Enjoy !!

Multiple Skype Accounts on Mac OS X

I needed to run multiple Skype instances on Mac OS X and here is the way to do it.

1. Create a new user from System Configuration > Users.

2. Login with this new user, might not be necessary, but I did it to see if everything is ok.

3. Go back to your normal user and open a Terminal.

4. Type su newuser. It will ask for the user’s password. Replace newuser with the user you created

5. Type /Applications/Skype.app/Contents/MacOS/Skype and the new Skype instance should appear in the dock

You have to leave the Terminal open, if you close the terminal the other Skype will close. Also note, that preferences and files are saved in the newuser‘s directory.

nohup /Applications/Skype.app/Contents/MacOS/Skype might also work to run Skype in the background so it’s not closed when the terminal is closed. Hope it saves you some time.

 

!!Enjoy!!

iPad2

Just under one year ago, Apple shocked the computing world with a 9.7-inch touchscreen tablet that few truly expected.

Some called the original Apple iPad a large-format iPhone. Others berated the name and made jokes that were not remotely funny.

The early reviews were marginal at best – we handed the device a solid four stars. Technical folks decried the lack of Adobe Flash and the missing cameras.

Now, 60,000 apps later (according to Apple, who counts every conceivable option) and just a few weeks after the first real Android 3.0 tablet contender hit the streets (Motorola Xoom), the iPad 2 has sauntered onto the playing field.

At 241mm tall, 186mm wide, and 8.6mm thick, the iPad 2 is just a hair smaller than the original iPad and it’s thinner than the iPhone 4. It has a curved edge that makes it look a bit more ‘space age’ and, surprisingly, easier to grasp because you can curve your fingers more easily around the bezel.
With rounded edges, iPad 2 has a more contoured look, shunning the straight edges of the original iPad.  According to Kevin Keller of IHS iSuppli, the slim appearance of iPad 2 not only makes the first iPad seem bulky, but also makes other tablet devices seem gargantuan compared to iPad 2.Despite having a slimmer battery, iPad 2 is roughly 15 percent more efficient in terms of power usage compared with the original.  Foregoing the two thick cells of the first iPad, Apple used three thinner, slimmer, cells, reducing the battery’s thickness.

For the screen, Apple did away with the metal sheet structure in favor of a touchscreen with an improved glass layer.  The glass on iPad 2 is thinner, more flexible and durable, than the screen of the original iPad according to IHS tests.

Compounding all of this is the cost advantage Apple has over its competitors.  UBM indicates that Apple reportedly only spent $270 to manufacture the 32GB iPad 2, cheaper compared to the estimated cost for the Motorola Xoom.

iPad 2 is smaller, faster and more feature-rich than the first generation iPad.  Moreover, with low costs, both to manufacture and to offer consumers, others can’t match, Apple and iPad should continue to dominate the tablet market.

Have you purchased iPad 2? 🙂

Customize TabBar in iPhone

When you add Tab Bar in your iPhone project, by default its background color is black and selection color is blue. But if you need to change it add these code in your project file RootViewController-

// RootViewController.h file

@interface UITabBar (ColorExtensions)

– (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;

@end

@interface UITabBarItem (Private)

@property(retain, nonatomic) UIImage *selectedImage;

– (void)_updateView;

@end

//RootViewController.m file

@implementation UITabBar (ColorExtensions)

– (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur

{

CGColorRef cgColor = [color CGColor];

CGColorRef cgShadowColor = [shadowColor CGColor];

for (UITabBarItem *item in [self items])

if ([item respondsToSelector:@selector(selectedImage)] &&

[item respondsToSelector:@selector(setSelectedImage:)] &&

[item respondsToSelector:@selector(_updateView)])

{

CGRect contextRect;

contextRect.origin.x = 0.0f;

contextRect.origin.y = 0.0f;

contextRect.size = [[item selectedImage] size];

// Retrieve source image and begin image context

UIImage *itemImage = [item image];

CGSize itemImageSize = [itemImage size];

CGPoint itemImagePosition;

itemImagePosition.x = ceilf((contextRect.size.width – itemImageSize.width) / 2);

itemImagePosition.y = ceilf((contextRect.size.height – itemImageSize.height) / 2);

UIGraphicsBeginImageContext(contextRect.size);

CGContextRef c = UIGraphicsGetCurrentContext();

// Setup shadow

CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor);

// Setup transparency layer and clip to mask

CGContextBeginTransparencyLayer(c, NULL);

CGContextScaleCTM(c, 1.0, -1.0);

CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [itemImage CGImage]);

// Fill and end the transparency layer

CGContextSetFillColorWithColor(c, cgColor);

contextRect.size.height = -contextRect.size.height;

CGContextFillRect(c, contextRect);

CGContextEndTransparencyLayer(c);

// Set selected image and end context

[item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()];

UIGraphicsEndImageContext();

// Update the view

[item _updateView];

}

}

@end

// in ViewDidLoad{

// Give the selection color and its shadow

[[[self tabBarController] tabBar] recolorItemsWithColor:[UIColor whiteColor] shadowColor:[UIColor blackColor] shadowOffset:CGSizeMake(0.0f, -1.0f) shadowBlur:3.0f];

}

It’s works great friends 🙂

!! Enjoy !!

Removing an App from iTunes Sales (App Store)

NOTE: Your app’s availability date ultimately determines if your app is live on the App Store or not. If your availability date is set to a date in the future, even if your app is Ready for Sale, it will not be live in the App Store until your availability date approaches.

Since Rights and Pricing settings are app level settings, when you choose to remove all App Store territory settings for an app, you will be removing the entire app from the App Store and not just a specific version.

Now follow these steps:

1. Login into your iTunes Connect with your developer id: https://itunesconnect.apple.com

2. Click on App Icon

3. Click on Rights And Pricing

4. At the bottom This app will be on sale in all App Stores worldwide.
Or, you can select specific stores “here”. Click on here button to open all specific app stores.

5. Click on the “Deselect All” button to uncheck all App Store territories.

6. Click on “Save Changes” button.

7. Now when you save all these and go to back to your App icon home screen. There will be one more button appear “Delete Application” after “Set Up iAd Network”.

8. Click on Delete button and read instructions.

9. Your App become disappear from app store withing 24 hours.

!! Enjoy !!

Great help for NSCalendar..

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[NSDate alloc] init]];

[components setHour:-[components hour]];
[components setMinute:-[components minute]];
[components setSecond:-[components second]];
NSDate *today = [cal dateByAddingComponents:components toDate:[[NSDate alloc] init] options:0]; //This variable should now be pointing at a date object that is the start of today (midnight);

[components setHour:-24];
[components setMinute:0];
[components setSecond:0];
NSDate *yesterday = [cal dateByAddingComponents:components toDate: today options:0];

components = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[[NSDate alloc] init]];

[components setDay:([components day] – ([components weekday] – 1))];
NSDate *thisWeek = [cal dateFromComponents:components];

[components setDay:([components day] – 7)];
NSDate *lastWeek = [cal dateFromComponents:components];

[components setDay:([components day] – ([components day] -1))];
NSDate *thisMonth = [cal dateFromComponents:components];

[components setMonth:([components month] – 1)];
NSDate *lastMonth = [cal dateFromComponents:components];

NSLog(@”today=%@”,today);
NSLog(@”yesterday=%@”,yesterday);
NSLog(@”thisWeek=%@”,thisWeek);
NSLog(@”lastWeek=%@”,lastWeek);
NSLog(@”thisMonth=%@”,thisMonth);
NSLog(@”lastMonth=%@”,lastMonth);

Creating UIColor objects from hex values

It’s pretty inconvenient to create UIColor objects while developing apps for the iPhone, as you need to specific separate values for the RGB parts: red, green, blue.
I found a trick online a few weeks ago on how to automatically generate that code, by simply using a mac
#define UIColorFromRGB(rgbValue) [UIColor

colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 

green:((float)((rgbValue & 0xFF00) >> 8))/255.0 

blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

The usage looks something like this:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

if (nil == cell) {

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];

}

cell.textColor = UIColorFromRGB(0x333333);

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

cell.text = @"Testing 1 2 3";

}

Steve Jobs:Three stories from my life

‘You’ve got to find what you love,’ Jobs says

This is the text of the Commencement address by Steve Jobs, CEO of Apple Computer and of Pixar Animation Studios, delivered on June 12, 2005.

I am honored to be with you today at your commencement from one of the finest universities in the world. I never graduated from college. Truth be told, this is the closest I’ve ever gotten to a college graduation. Today I want to tell you three stories from my life. That’s it. No big deal. Just three stories.

1.The first story is about connecting the dots.

I dropped out of Reed College after the first 6 months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out?

It started before I was born. My biological mother was a young, unwed college graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife. Except that when I popped out they decided at the last minute that they really wanted a girl. So my parents, who were on a waiting list, got a call in the middle of the night asking: “We have an unexpected baby boy; do you want him?” They said: “Of course.” My biological mother later found out that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would someday go to college.

And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents’ savings were being spent on my college tuition. After six months, I couldn’t see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn’t interest me, and begin dropping in on the ones that looked interesting.

It wasn’t all romantic. I didn’t have a dorm room, so I slept on the floor in friends’ rooms, I returned coke bottles for the 5¢ deposits to buy food with, and I would walk the 7 miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example:

Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn’t have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can’t capture, and I found it fascinating.

None of this had even a hope of any practical application in my life. But ten years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts. And since Windows just copied the Mac, its likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on this calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards ten years later.

Again, you can’t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something — your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.

2. My second story is about love and loss.
I was lucky — I found what I loved to do early in life. Woz and I started Apple in my parents garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a $2 billion company with over 4000 employees. We had just released our finest creation — the Macintosh — a year earlier, and I had just turned 30. And then I got fired. How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him. So at 30 I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating.

I really didn’t know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down – that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me — I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over.

I didn’t see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life.

During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the worlds first computer animated feature film, Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, I returned to Apple, and the technology we developed at NeXT is at the heart of Apple’s current renaissance. And Laurene and I have a wonderful family together.

I’m pretty sure none of this would have happened if I hadn’t been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometimes life hits you in the head with a brick. Don’t lose faith. I’m convinced that the only thing that kept me going was that I loved what I did. You’ve got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don’t settle.


3. My third story is about death

When I was 17, I read a quote that went something like: “If you live each day as if it was your last, someday you’ll most certainly be right.” It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: “If today were the last day of my life, would I want to do what I am about to do today?” And whenever the answer has been “No” for too many days in a row, I know I need to change something.

Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything — all external expectations, all pride, all fear of embarrassment or failure – these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.

About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn’t even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctor’s code for prepare to die. It means to try to tell your kids everything you thought you’d have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.

I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach and into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and I’m fine now.

This was the closest I’ve been to facing death, and I hope its the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept:

No one wants to die. Even people who want to go to heaven don’t want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life’s change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true.

Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma — which is living with the results of other people’s thinking. Don’t let the noise of others’ opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.

When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960’s, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: it was idealistic, and overflowing with neat tools and great notions.

Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: “Stay Hungry. Stay Foolish.” It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.

Stay Hungry. Stay Foolish.

Nokia 5530 Secret Codes:

*#0000# – Entering this code gives the firmware version of your phone’s software.Check your firmware version and make sure that you have the latest updated firmware.Newer firmware is made in order to rectify bugs and provide new features.

*#06# – IMEI(International Mobile Equipment Identity)Number – IMEI number is like Finger print.Each mobile phone has a unique IMEI number. *#7780# – This code restores the original factory settings without affecting any of your files.It is also called soft reset.

*#7370# – This code will completely format your phone deleting all your files.It will take your software to the same state, as you first received your phone.Use this code only if something wrong happens with your phone’s software like virus attack.It is also called hard reset.

*#2820# – This code tells your device’s bluetooth ID.It can be used for manually adding bluetooth devices.

*#62209526# – Shows MAC address of the WLAN adapter.This will be useful while connecting to internet through your phone’s Wifi connection.

*#92702689# – Life Timer – Shows total call minutes since very first call.