Monday, June 8, 2015

[iOS] Making fancy view with border, corner and shadow


self.imageView.layer.borderColor        = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1].CGColor;
self.imageView.layer.borderWidth        = 1;
self.imageView.layer.cornerRadius       = 3.0;
self.imageView.layer.masksToBounds      = YES;
self.imageView.layer.shouldRasterize    = YES;
self.imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;

self.imageViewBG.layer.shadowOffset       = CGSizeMake(1, 1);
self.imageViewBG.layer.shadowRadius       = 1;
self.imageViewBG.layer.shadowOpacity      = 0.1;
self.imageViewBG.layer.cornerRadius       = 3.0;
self.imageViewBG.layer.masksToBounds      = NO;
self.imageViewBG.layer.shouldRasterize    = YES;
self.imageViewBG.layer.rasterizationScale = [UIScreen mainScreen].scale;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.imageViewBG.bounds cornerRadius:3.0];
self.imageViewBG.layer.shadowPath = path.CGPath;

Wednesday, April 8, 2015

[iOS] How to get top most view controller?

+ (UIViewController *)topViewController
{
    return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}

+ (UIViewController *)topViewController:(UIViewController *)rootViewController
{
    if (rootViewController.presentedViewController == nil) {
        return rootViewController;
    }
    if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
        UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
        return [self topViewController:lastViewController];
    }
    UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
    return [self topViewController:presentedViewController];
}

+ (UINavigationController *)navigationController
{
    UIViewController *topViewController = [self topViewController];
    UINavigationController *navigationController = nil;
    if ([topViewController isKindOfClass:[UINavigationController class]])
    {
        navigationController = (UINavigationController *)topViewController;
    }else
    {
        navigationController = topViewController.navigationController;
    }

    return navigationController;
}

[iOS] How to open a native app or Appstore from Safari or UIWebView


1. Promoting App Banner:
smartbanner_2x.png

2. Take user to Appstore from Safari link: