Skip to content

Instantly share code, notes, and snippets.

View MaximAlien's full-sized avatar

Maxim Makhun MaximAlien

View GitHub Profile
@MaximAlien
MaximAlien / AnimView
Created November 4, 2015 15:27
[iOS] [CAAnimation] Simple animation of the view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 50, 50)];
[view setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:view];
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.x";
animation.fromValue = @0;
animation.toValue = @(self.view.frame.size.width);
animation.duration = 1;
animation.fillMode = kCAFillModeForwards;
@MaximAlien
MaximAlien / iOSDebugCheck
Created November 16, 2015 08:20
[iOS] Check for Debug/Release
#if DEBUG
println("debug")
#else
println("Not debug")
#endif
@MaximAlien
MaximAlien / iOSUITableViewStub
Last active June 1, 2017 16:53
[iOS] Stub used for quick UITableView integration
// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
@MaximAlien
MaximAlien / iOSUICollectionViewStub
Last active December 24, 2015 12:12
[iOS] Stub used for quick UICollectionView integration
// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@end
@MaximAlien
MaximAlien / iOSNavBarButtonItem
Created December 2, 2015 12:24
[iOS] Set right navigation bar item button
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(done)];
[self.navigationItem setRightBarButtonItem:doneButton];
}
- (void)done
{
@MaximAlien
MaximAlien / iOSLayoutConstraintsFill
Created December 3, 2015 21:40
[iOS] Layout constraints to fill view in parent
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.tableView];
@MaximAlien
MaximAlien / DelegationUsingProtocol
Created December 3, 2015 21:56
[iOS] Delegation example
@protocol ExampleViewDelegate <NSObject>
- (void)doAction;
@end
@interface ExampleView : UIView
@property (assign) id<ExampleViewDelegate> delegate;
@MaximAlien
MaximAlien / AttrStrForButton
Last active May 24, 2019 15:08
[iOS] Attributed string for UIButton
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"test1"];
[attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, [attributeString length])];
[attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15.0f] range:NSMakeRange(0, [attributeString length])];
NSMutableAttributedString *attributeNewString = [[NSMutableAttributedString alloc] initWithString:@"test2"];
[attributeString appendAttributedString:attributeNewString];
self.testButton.titleLabel.attributedText = attributeString;
// Image attachment
@MaximAlien
MaximAlien / HandleRotation
Created December 8, 2015 14:50
[iOS] Delegate method to handle rotation
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
}];
}
@MaximAlien
MaximAlien / ImageFromColor
Created December 9, 2015 07:54
[iOS] Category which is used to create UIImage * from UIColor
@implementation UIImage (ImageFromColorCategory)
+ (UIImage *)imageFromColor:(UIColor *)color withSize:(CGSize)size
{
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();