Skip to content

Instantly share code, notes, and snippets.

View markSci5's full-sized avatar

Mark Dhem S. Mansueto markSci5

View GitHub Profile
@markSci5
markSci5 / ShowTextFieldViewController.m
Created August 29, 2013 03:12
Adjust view to show fields when keyboard appears
#pragma mark - UITextField Delegates
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
self.activeTextField = textField;
}
#pragma mark - Keyboard Notification Methods
@markSci5
markSci5 / transparent_webview
Created August 24, 2013 05:45
Make web view transparent
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
@markSci5
markSci5 / assign_weak
Created August 21, 2013 11:00
Assigning ui element to weak property
@property (nonatomic, weak) KGModalContainerView *containerView;
...
-(void)viewDidLoad {
[super viewDidLoad];
KGModalContainerView *myContainerView = [[KGModalContainerView alloc] initWithFrame:containerViewRect]; // This is a strong reference to that view
[self.view addSubview:myContainerView]; //Here self.view retains myContainerView
self.containerView = myContainerView; // Now self.containerView has weak reference to that view, but if your self.view removes this view, self.containerView will automatically go to nil.
// In the end ARC will release myContainerView, but it's retained by self.view and weak referenced by self.containerView
}
@markSci5
markSci5 / progress_navbar
Created August 21, 2013 10:56
Add progress bar to nav bar
- (void)progress:(int)progress withMessage:(NSString*)message {
UIView* v = [[[UIView alloc] init] autorelease];
v.frame = CGRectMake(0, 0, 200, 30);
v.backgroundColor = [UIColor clearColor];
UILabel* lbl = [[[UILabel alloc] init] autorelease];
lbl.frame = CGRectMake(0,0, 200, 15);
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor whiteColor];
lbl.shadowColor = [UIColor colorWithWhite:0 alpha:0.3];
@markSci5
markSci5 / modify_view_nav_bar
Created August 21, 2013 09:14
Modify iOS navigation bar for only one view
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
@markSci5
markSci5 / GCD-background-main-thread
Created August 19, 2013 07:37
GCD background and main thread task
//Start an activity indicator here
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Call your function or whatever work that needs to be done
//Code in this part is run on a background thread
dispatch_async(dispatch_get_main_queue(), ^(void) {
//Stop your activity indicator or anything else with the GUI
@markSci5
markSci5 / new_gist_file
Created August 19, 2013 05:45
Manual tab switching
// Custom tab bar implementation from http://www.wiredbob.com/2009/04/iphone-tweetie-style//-navigation.html
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item == favouritesTabBarItem) {
UIViewController *fabViewController = [viewControllers objectAtIndex:0];
[self.selectedViewController.view removeFromSuperview];
[self.view addSubview:fabViewController.view];
self.selectedViewController = fabViewController;
} else if (item == moreTabBarItem) {
UIViewController *moreViewController = [viewControllers objectAtIndex:1];
@markSci5
markSci5 / hide-tab-bar
Created August 19, 2013 04:27
Hide the tab bar when pushing a new controller.
// Create the UIViewController
MyViewController * viewController = [[MyViewController alloc] init];
// Hide the tab bar
viewController.hidesBottomBarWhenPushed = YES;
// Push onto the view stack
[[self navigationController] pushViewController:viewController animated:YES];
@markSci5
markSci5 / Instructions
Created August 13, 2013 02:56
Convert iPhone storyboard to iPad.
1. Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard
2. Open this file any text editor.
3. Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
4. Now save everything and reopen Xcode -> the iPad-Storyboard contains the same as the iPhone-file but everyting could be disarranged
@markSci5
markSci5 / git-push-all
Created August 13, 2013 02:09
Push all remote branches and their tags
git push --all
git push --tags