Posts

Showing posts from 2015

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

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

[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 topVi...

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

Image
1. Promoting App Banner: https://developer.apple.com/ library/ios/documentation/ AppleApplications/Reference/ SafariWebContent/ PromotingAppswithAppBanners/ PromotingAppswithAppBanners. html http://stackoverflow.com/ questions/6964515/launching- app-or-app-store-from-safari 2. Take user to Appstore from Safari link: http://applinks.org/ documentation/ https://www. brandbuilderwebsites.com/blog/ 2014/05/01/mobile-app-linking/ https://developers.facebook. com/products/app-links

[iOS] Draw Dashed Border Around View

+ (void)drawDashedBorderAroundView:(UIView *)v cornerRadius:(CGFloat)cornerRadius borderWidth:(CGFloat)borderWidth dashPattern1:(NSInteger)dashPattern1 dashPattern2:(NSInteger)dashPattern2 lineColor:(UIColor*)lineColor { //border definitions // CGFloat cornerRadius = 10; // CGFloat borderWidth = 2; // NSInteger dashPattern1 = 4; // NSInteger dashPattern2 = 8; // UIColor *lineColor = [UIColor grayColor]; CGRect newR = v.frame; newR.origin.x += borderWidth/2; newR.origin.y += borderWidth/2; newR.size.width -= borderWidth; newR.size.height -= borderWidth; v.frame = newR; //drawing CGRect frame = v.bounds; CAShapeLayer *_shapeLayer = [CAShapeLayer layer]; //creating a path CGMutablePathRef path = CGPathCreateMutable(); //drawing a border around a view CGPathMoveToPoint(path, NULL, 0, frame.size.height -...