Skip to content

Instantly share code, notes, and snippets.

View zld's full-sized avatar
👻

zld zld

👻
View GitHub Profile
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY < 0) {
[scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
}
}
+ (BOOL)isJailbroken {
BOOL jailbroken = NO;
NSString *cydiaPath = @"/Applications/Cydia.app";
NSString *aptPath = @"/private/var/lib/apt/";
if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) {
jailbroken = YES;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {
jailbroken = YES;
}
@zld
zld / gist:852328ad93e4f0b30688
Created May 28, 2015 12:37
While using grouped TableView use this to avoid border cutting
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
@zld
zld / TopViewController.m
Created May 29, 2015 03:06
Get the top ViewController from current View.
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@zld
zld / adjustTabBarLabelPosition.m
Created May 29, 2015 07:41
Adjust position of UITabBarItem's label
for (UITabBarItem* item in self.tabBarController.tabBar.items)
{
[item setTitlePositionAdjustment:UIOffsetMake(0, -3)];
}
@zld
zld / weakSelf.m
Created June 2, 2015 04:25
weak self for block
#define ZLDWeak(agWeak,obj) __block __unsafe_unretained typeof (&*obj) agWeak = obj
@zld
zld / NullToNil.m
Created June 10, 2015 03:19
Deal with Null
#define PASS_NULL_TO_NIL (instance)(([instance isKindOfClass:[NSNull class]]) ? nil : instance)
UIImage *image = ...;
//Have the image draw itself in the correct orientation if necessary
if(!(image.imageOrientation == UIImageOrientationUp ||
image.imageOrientation == UIImageOrientationUpMirrored))
{
CGSize imgsize = image.size;
UIGraphicsBeginImageContext(imgsize);
[image drawInRect:CGRectMake(0.0, 0.0, imgsize.width, imgsize.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
@zld
zld / ChangeSectionSeparateSpace.m
Created June 17, 2015 04:22
Change space between sections in tableView
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 6;
return 1.0;
}
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 5.0;