Skip to content

Instantly share code, notes, and snippets.

View engmsaleh's full-sized avatar

Mohamed Saleh Zaied engmsaleh

View GitHub Profile
NSDate *timenow=[NSDate date];
NSLog(@"Date before date2dot net=%@",[timenow description]);
NSString *date2DotNet=[timenow dateToDotNet];
NSLog(@"Dot net version of now = %@",date2DotNet);
timenow=[NSDate dateFromDotNet:date2DotNet];
NSLog(@"Date back from date2dot net=%@",[timenow description]);
@engmsaleh
engmsaleh / mr-save-patterns.md
Last active August 29, 2015 14:26 — forked from tonyarnold/mr-save-patterns.md
Common save patterns for use with MagicalRecord

Common Save Patterns

Standard background save

Assuming that you don't care which NSManagedObjectContext is used, and you just want to make some changes and save them in the background, use the following method. 90% of the time, this is what you'll want.

NSManagedObjectSubclass *myObject = [NSManagedObjectSubclass MR_findFirst];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
@engmsaleh
engmsaleh / gist:be0b4ba50ab94929b17a
Last active August 29, 2015 14:28 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@engmsaleh
engmsaleh / info.plist
Created October 6, 2015 19:05 — forked from jonalter/info.plist
iOS: launch your app from another app
// info.plist from Test 5
// Open your info.plist and look for CFBundleURLSchemes
// this is the string that you will use to open that app
// You can also copy the info.plist to the root of your app and edit it.
// You can even have multiple schemes that you can use to launch it.
// Here I can launch the app using either 'test5://' or 'pedro://'
// Be SURE to do a clean build
<key>CFBundleURLSchemes</key>
<array>
@engmsaleh
engmsaleh / gist:c7ecb5696e943d3da3ab
Created November 11, 2015 19:25 — forked from omz/gist:1102091
Creating arbitrarily-colored icons from a black-with-alpha master image (iOS)
// Usage example:
// input image: http://f.cl.ly/items/3v0S3w2B3N0p3e0I082d/Image%202011.07.22%2011:29:25%20PM.png
//
// UIImage *buttonImage = [UIImage ipMaskedImageNamed:@"UIButtonBarAction.png" color:[UIColor redColor]];
// .h
@interface UIImage (IPImageUtils)
+ (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color;
@end
@engmsaleh
engmsaleh / gist:6fa1f2ac1e572631cde4
Created November 13, 2015 09:33
Add Text on UIImage and return new UIImage
- (UIImage*)image:(UIImage*)image withText:(NSString*)text
{
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[image drawInRect:rect];
/// Make a copy of the default paragraph style
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
/// Set line break mode
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
expr (void)NSLog(@"indexPath row: %ld", (long int)[indexPath row])
@engmsaleh
engmsaleh / uiappearance-selector.md
Created November 16, 2015 18:12 — forked from mattt/uiappearance-selector.md
A list of methods and properties conforming to `UIAppearance` as of iOS 8.0

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

UIActivityIndicatorView

@engmsaleh
engmsaleh / gist:ede0a358dcdd3c209497
Last active December 23, 2015 13:19
Apply tint color on UIImage inside UIImageView
// Source http://mikethinkingoutloud.com/color-a-uiimage/
// init the image using imageWithRenderingMode set to AlwaysTemplate
UIImage *image = [[UIImage imageNamed:@"checkmark"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
// put UIImage in a UIImageView and adjust color with tintColor
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.tintColor = [UIColor redColor];
@engmsaleh
engmsaleh / gist:3568f97acda9910683cc
Created December 23, 2015 19:16
Make UIToolBar transparent
if ([self.shareFooterToolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[self.shareFooterToolBar setBackgroundImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
}
if ([self.shareFooterToolBar respondsToSelector:@selector(setShadowImage:forToolbarPosition:)]) {
[self.shareFooterToolBar setShadowImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny];
}