Skip to content

Instantly share code, notes, and snippets.

View MaximAlien's full-sized avatar

Maxim Makhun MaximAlien

View GitHub Profile
@MaximAlien
MaximAlien / RandomNumber
Created December 26, 2015 12:32
[iOS] Random number
NSInteger randomNumber = arc4random() % 3;
switch (randomNumber)
{
case 0:
break;
case 1:
break;
@MaximAlien
MaximAlien / Signleton
Created January 2, 2016 18:16
[Objective-C] Singleton Design Pattern
// Singleton.h
#import <Foundation/Foundation.h>
@interface Singleton : NSObject
+ (Singleton *)sharedInstance;
@end
@MaximAlien
MaximAlien / Builder
Last active January 2, 2016 21:11
[Objective-C] Builder Design Pattern
// Builder.h
#import <Foundation/Foundation.h>
@interface ObjectBuilder : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSNumber *age;
@end
@MaximAlien
MaximAlien / NSLogUIView
Created January 13, 2016 10:38
[iOS] NSLog frame of the UIView
NSLog(@"Frame: %@", NSStringFromCGRect(customView.frame));
@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];
@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 / 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 / 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 / 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 / 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;
}