Skip to content

Instantly share code, notes, and snippets.

@sanketfirodiya
sanketfirodiya / gist:f969f51581d775e24dac
Last active August 29, 2015 14:03
iOS device type determination
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
} else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
}
@sanketfirodiya
sanketfirodiya / gist:a21a4bd5f5f274154e43
Last active August 29, 2015 14:03
iOS orientation determination
if (UIInterfaceOrientationIsPortrait(orientation)) {
} else if (UIInterfaceOrientationIsLandscape(orientation)) {
}
@sanketfirodiya
sanketfirodiya / gist:22cd81bb57057b0ebccf
Last active August 29, 2015 14:03
Remove subviews from view
for (UIView *subView in self.uiGOButton.subviews) {
if (subView.tag == 10) {
[subView removeFromSuperview];
}
}
@sanketfirodiya
sanketfirodiya / gist:52881274e3da868b697f
Last active August 29, 2015 14:03
Scroll up UITableView when keyboard is shown
- (void)keyboardWillBeShown:(NSNotification*)aNotification{
CGFloat mainViewScrollUp;
NSDictionary* info = [aNotification userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
mainViewScrollUp = keyboardSize.height;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
self.uiTableView.contentInset = contentInsets;
self.uiTableView.scrollIndicatorInsets = contentInsets;
@sanketfirodiya
sanketfirodiya / gist:4c227a47d3b816f008f6
Last active August 29, 2015 14:03
Hide keyboard on UITextField return key
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
@sanketfirodiya
sanketfirodiya / gist:a948d4cbabe28ee76904
Last active August 29, 2015 14:03
Scroll down UITableView when keyboard is dismissed
- (void)keyboardWillBeHidden:(NSNotification*)aNotification{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[UIView animateWithDuration:0.25f
animations:^{
self.uiTableView.contentInset = contentInsets;
self.uiTableView.scrollIndicatorInsets = contentInsets;
}
];
}
dispatch_queue_t secondaryQueue = dispatch_queue_create("com.appname.object", NULL);
dispatch_async(secondaryQueue, ^{
// execute code on non-UI thread
dispatch_async(dispatch_get_main_queue(), ^{
// execute code on UI thread
});
});
@sanketfirodiya
sanketfirodiya / gist:e94039eff31f8c6ebbac
Last active August 29, 2015 14:03
Sample URL scheme for email
<a href="openApp://">Open App</a>
@sanketfirodiya
sanketfirodiya / gist:9b24268a9372d24a6c7f
Last active August 29, 2015 14:03
HeaderView for UITableView
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.frame.size.width, 18)];
[headerLabel setFont:[UIFont boldSystemFontOfSize:12]];
headerLabel.textColor = [UIColor darkGrayColor];
headerLabel.text = @"Share with friends";
[headerView addSubview:headerLabel];
headerView.backgroundColor = [UIColor clearColor];
return headerView;
@sanketfirodiya
sanketfirodiya / gist:ebad56de5b49a0cbfc70
Last active August 29, 2015 14:03
Fake push notification banner for in-app notifications
- (void)showFakePushNotificationAnimation:(NSNotification *)notification {
if (notification) {
NSString *message = [NSString stringWithFormat:@"%@", [[[notification object] objectForKey:@"aps"] objectForKey:@"alert"]];
UIToolbar *newmessageBannerView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -BANNER_HEIGHT, self.view.frame.size.width, BANNER_HEIGHT)];
newmessageBannerView.translucent = YES;
newmessageBannerView.barTintColor = [UIColor colorWithWhite:0.074 alpha:0.550];
UILabel *bannerLabel = [[UILabel alloc] initWithFrame:CGRectMake(44.0, 10.0, 320.0, 22.0)];