About Muzammil

WHO I AM? Hi, I am Muzammil Mohammad. I am here to share my knowledge with all mobile application developers and those companies who are stuck on development (due to bad quality of code or don't know what to do) or want to know how to build a good mobile app. I believe I am more expert in UI and Architecture design of mobile app. So if you need my helps or assistant for your mobile app projects, Feel free to contact me. I will try my best to improve the quality of your app. Or you can hire me to develop your apps. I’d love to talk with you. Best Regards

Resize table cell according to text length

Some times we need to customize our table cell’s height according to text length. For long text we need to make a bigger cell and vice versa. Here is the method to do this:

1. define you table cell’s size and font:

#define CONST_Cell_height 50.0f
#define CONST_Cell_width 270.0f
#define CONST_textLabelFontSize     16
#define CONST_detailLabelFontSize   14

2. Here is the method to calculate table cell width:

– (int) heightOfCellWithTitle :(NSString*)titleText
andSubtitle:(NSString*)subtitleText
{
CGSize titleSize = {0, 0};
CGSize subtitleSize = {0, 0};

if (titleText && ![titleText isEqualToString:@””])
titleSize = [titleText sizeWithFont:[UIFont boldSystemFontOfSize:16]
constrainedToSize:CGSizeMake(CONST_Cell_width, 4000)
lineBreakMode:UILineBreakModeWordWrap];

if (subtitleText && ![subtitleText isEqualToString:@””])
subtitleSize = [subtitleText sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:CGSizeMake(CONST_Cell_width, 4000)
lineBreakMode:UILineBreakModeWordWrap];

descriptionLabelHeight = subtitleSize.height;

return titleSize.height + subtitleSize.height;
}

3. Use this in your table height for row:

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *title = @”Yor cell title”;
NSString *subtitle =@”Your cell subtitle”;

int height =  “some constant” + [self heightOfCellWithTitle:title andSubtitle:subtitle]; // some constant is used to adjust cell height. may be zero.

return (height < CONST_Cell_height ? CONST_Cell_height : height);

}

it will resize the table cell according to text size.

!! Enjoy !!

How to create a password-protected (encrypted) disk image in Mac OS X 10.3 or later

You can move files to or from an encrypted disk image as easily as you can from a non-encrypted disk image. Follow these steps to create an encrypted disk image:

  1. Open Disk Utility (/Applications/Utilities/).
  2. Mac OS X 10.4, 10.5 or later: Click the New Image button, or choose New > Blank Disk Image from the Disk Utility File menu.
    Mac OS X 10.3 through 10.3.9: Choose New from the Disk Utility Image menu.
  3. Enter a name in the Save As field. This name is used for the disk image (.dmg) file.
  4. Change the save destination if you wish to.
  5. Select a size for the image file from the Volume Size pop-up menu (Size in Mac OS X 10.3) .
  6. Choose a volume format if you don’t want to use the default Mac OS X Extended (Journaled).
  7. Choose an image format. You can use “sparse disk image” for a disk image that only uses as much space as it needs, rather than a set amount of space. If you’re not sure, use “read/write disk image” choice.
  8. Choose 128-bit AES (and/or 256-bit AES in Mac OS X 10.5 or later) from the Encryption pop-up menu to encrypt the image’s contents with a password. If you don’t choose an encryption, your new image won’t be encrypted.
  9. Click the Create button.
  10. Enter and verify a good password in the dialog window that appears. This password will be saved in your keychain by default, or you can deselect “Remember password (add to keychain)” if you don’t want that. You can store the password in the keychain both for convenience and for reducing risk of password loss.
  11. Click OK.

Important: If you forget the password, data stored in the encrypted disk image cannot be retrieved. If you have saved the password in the keychain file, the password will be available to you there.

 

!! Cheers !!

XCode4 hangs at “Attaching to ….”

Sometimes when you rename you app XCode4 hang while running app on simulator. And it stuck at “Attaching to ‘app name’ “. Here is the step how to fix it:

1. Clicking on the project name in the left pane (at the very top). This will bring up a new menu to the right, something like the project/ target editors in XCode4

2. Click on Target and Click on Build Settings up at the top.

3. Under Packaging make sure your product name is the same for every build, and equal to whatever it says it’s attaching to. Eg if XCode is Hanging at “Attaching to Lasso Tool” but your product name is “Alter Image” then it won’t build.

That was exactly my problem because I renamed my app half way through development.

!! Cheers !!

Masking of Image on another image

Here is a small core graphics method for masking of images:

 

– (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

CGContextRef mainViewContentContext;
CGColorSpaceRef colorSpace;

colorSpace = CGColorSpaceCreateDeviceRGB();

// create a bitmap graphics context the size of the image
mainViewContentContext = CGBitmapContextCreate (NULL, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);

// free the rgb colorspace
CGColorSpaceRelease(colorSpace);

CGImageRef maskingImage = [maskImage CGImage];
CGContextClipToMask(mainViewContentContext, CGRectMake(0, 0, maskImage.size.width, maskImage.size.height), maskingImage);
CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, image.size.width, image.size.height), self.CGImage);

// Create CGImageRef of the main view bitmap content, and then
// release that bitmap context
CGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext);

// convert the finished resized image to a UIImage
UIImage *theImage = [UIImage imageWithCGImage:mainViewContentBitmapContext];
// image is retained by the property setting above, so we can
// release the original

CGContextRelease(mainViewContentContext);
CGImageRelease(mainViewContentBitmapContext);
maskingImage = nil;
CGImageRelease(maskingImage);
// return the image
return theImage;

}

For more detail about masking please checkout Quartz 2D developer guide:

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html

 

!! Enjoy !!

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);