Pages

Wednesday, October 9, 2013

Font Family Check in Xcode



NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
    NSLog(@”Family name: %@”, [familyNames objectAtIndex:indFamily]);
    fontNames = [[NSArray alloc] initWithArray:
                 [UIFont fontNamesForFamilyName:
                  [familyNames objectAtIndex:indFamily]]];
    for (indFont=0; indFont<[fontNames count]; ++indFont)
    {
        NSLog(@” Font name: %@”, [fontNames objectAtIndex:indFont]);
    }
    [fontNames release];

}


Tuesday, October 8, 2013

Move NavigationController for iOS7

Converting iOS 6 app to iOS 7 there is a problem with top navigation for iOS 7. So i found a solution for this. 

Note: Although there are a lot of solutions for this like delta updating in NIB file. but i found this useful and applied in my current project as well.

It should be added in AppDeletegate Class and in didFinishLaunchingWithOptions function before return YES;

    CGRect aRect = self.navigationController.view.frame;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
        aRect.origin.y = 20.0f;
        aRect.size.height -= aRect.origin.y;
    }
    else
    {
        aRect.origin.y = 0.0;
    }
    self.navigationController.view.frame = aRect;
    [self.window setBackgroundColor:[UIColor whiteColor]];

Thursday, October 3, 2013

Hide Keyboard for presentViewController

Hi, i found an issue that if you are using presentViewController then resignFirstResponder doesn't hide the keyboard. We can follow the below method for hiding keyboard

Just write the below code and add resignFirstResponder. it should work then 
-(BOOL)disablesAutomaticKeyboardDismissal{
    return NO;

}

Tuesday, October 1, 2013

UIActionSheet Menu in Xcode


To Show a Menu Sheet like below

We have to code as below

1. First of all, we need to add <UIActionSheetDelegate> delegate in class .h file

2. Now we have to code like below

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
actionSheet.tag = 1;
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
if ([window.subviews containsObject:self.view]) {
    [actionSheet showInView:self.view];
} else {
    [actionSheet showInView:window];

}


Wednesday, September 25, 2013

Align UIImageView Center dynamically in xCode

Suppose we have an UIImageView with name imageView and have to set this in center dynamically then we can follow the below step

[imageView setImage:[UIImage imageNamed:@"imageName.png"]];
imageView.autoresizingMask = UIViewAutoresizingNone;

imageView.contentMode = UIViewContentModeCenter;

Monday, September 23, 2013

CREATION OF IMAGE VIEW IN CIRCLE

Creation of image like below.
Image 
1. Take an UIImageView in .xib or storyboard file.
2. Link that name as you want. (Here i have taken imageView_AuthorPhoto)
Now code the below for make that in circular
imageView_AuthorPhoto.layer.masksToBounds = YES;
imageView_AuthorPhoto.layer.cornerRadius = imageView_AuthorPhoto.bounds.size.width/2;
imageView_AuthorPhoto.layer.borderWidth = 1.0;
imageView_AuthorPhoto.layer.borderColor =[UIColor colorWithRed:13/255 green:70/255 blue:131/255 alpha:1.0].CGColor;

And Set Image Accordingly
[imageView_AuthorPhoto  setImageWithURL:[NSURL   URLWithString:@"imageurl"] placeholderImage: useCache:<#(BOOL)#>];

Wednesday, September 18, 2013

Crop Image from an Image in Objective C

Here is the code to cut a piece from an Image or say UIImage

+ (UIImage *)cropImage:(UIImage *)image withArea:(CGRect)rect andScale:(int) scale{
    rect = CGRectMake(rect.origin.x*scale,
                      rect.origin.y*scale,
                      rect.size.width*scale,
                      rect.size.height*scale);
    
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage *img = [UIImage imageWithCGImage:imageRef
                                       scale:scale
                                 orientation:image.imageOrientation];
    CGImageRelease(imageRef);
    return img;
}