Skip to content

Instantly share code, notes, and snippets.

View MaximAlien's full-sized avatar

Maxim Makhun MaximAlien

  • San Francisco, CA
View GitHub Profile
@MaximAlien
MaximAlien / GCDBackgroundUpdate
Created September 7, 2016 10:06
[iOS] GCD method to update UI from background thread
dispatch_async(dispatch_get_main_queue(), ^{
// update UI here
});
@MaximAlien
MaximAlien / AlertDialogAndroid
Created August 19, 2016 13:07
[Android] Code which creates AlertDialog on Android
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Title")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
@MaximAlien
MaximAlien / SleepThread
Created April 25, 2016 13:41
[Android] Sleep to be able to attach to process
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
@MaximAlien
MaximAlien / TransitionController
Created April 15, 2016 17:05
[iOS] Class for view controller transitioning
@import Foundation;
@import UIKit;
@interface FIQTransitionDismissalController : NSObject <UIViewControllerAnimatedTransitioning>
@end
//------------------
#import "FIQTransitionDismissalController.h"
@MaximAlien
MaximAlien / DiffSizeImage
Created February 12, 2016 11:24
[iOS] Create new image with different size
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@MaximAlien
MaximAlien / UIActivityIndicatorView
Created January 20, 2016 20:42
[iOS] Show UIActivityIndicatorView
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.frame = CGRectMake(0.0f, 0.0f, 40.0f, 40.0f);
activityIndicatorView.center = self.view.center;
[self.view addSubview:activityIndicatorView];
[activityIndicatorView bringSubviewToFront:self.view];
[activityIndicatorView startAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
@MaximAlien
MaximAlien / MoveCellAtIndex
Created January 20, 2016 20:38
[iOS] Move UITableViewCell in UITableView
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] toIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
@MaximAlien
MaximAlien / ViewControllerFromStoryboard
Created January 19, 2016 14:03
[iOS] UIViewController creation which has xib in storyboard
CustomViewController *customViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomViewController"];
[self.navigationController showViewController:customViewController sender:nil];
@MaximAlien
MaximAlien / ActivityOrientation
Created January 13, 2016 20:33
[Android] Check current orientation
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
}
@MaximAlien
MaximAlien / ButtonImageColor
Created January 13, 2016 12:09
[iOS] Code which controls UIImage colour by changing tint colour of the UIButton.
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
UIImage *image = [[UIImage imageNamed:@"image_res"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[button setImage:image forState:UIControlStateNormal];
[button setTintColor:[UIColor whiteColor]];
[self addSubview:button];