Skip to content

Instantly share code, notes, and snippets.

View MaximAlien's full-sized avatar

Maxim Makhun MaximAlien

View GitHub Profile
@MaximAlien
MaximAlien / NSLogUIView
Created January 13, 2016 10:38
[iOS] NSLog frame of the UIView
NSLog(@"Frame: %@", NSStringFromCGRect(customView.frame));
@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 / 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 / RandomNumber
Created December 26, 2015 12:32
[iOS] Random number
NSInteger randomNumber = arc4random() % 3;
switch (randomNumber)
{
case 0:
break;
case 1:
break;
@MaximAlien
MaximAlien / GestureRecognizerExample
Created December 24, 2015 07:49
[iOS] UITapGestureRecognizer example on UIView
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handler:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
@MaximAlien
MaximAlien / ViewAnimationStubs
Created December 24, 2015 07:43
[iOS] UIView animation stubs
[UIView animateWithDuration:1.0f animations:^{
}];
[UIView animateWithDuration:1.0f animations:^{
} completion:^(BOOL finished) {
}];
@MaximAlien
MaximAlien / UIImageView
Created December 22, 2015 10:00
[iOS] UIImageView creation
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
imageView.image = [UIImage imageNamed:@"custom_image"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.bounds = CGRectInset(imageView.frame, 20.0f, 20.0f);
[self.navigationController.navigationBar addSubview:imageView];
@MaximAlien
MaximAlien / ViewControllerPresentation
Created December 21, 2015 16:00
[iOS] Change corner radius and size of the UIViewController presented modally
// For UIViewController inside UINavigationController
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.navigationController.view.superview.bounds = CGRectMake(0, 0, 300, 300);
self.navigationController.view.superview.layer.cornerRadius = 2.0f;
}
// Usual presentation
@MaximAlien
MaximAlien / RotationAnimation
Created December 21, 2015 10:29
[iOS] Rotation animation using CABasicAnimation
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.duration = 2.0f;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.additive = YES;
rotationAnimation.fromValue = [NSNumber numberWithFloat:0];
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI];
rotationAnimation.fillMode = kCAFillModeForwards;
[self.customView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
@MaximAlien
MaximAlien / ModalPresentation
Created December 16, 2015 11:19
[iOS] Modal UIViewController presentation (as UIModalPresentationFormSheet)
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];