Coder Social home page Coder Social logo

p34utils's Introduction

Some useful categories for Cocoa classes and other small utils classes, that can be used in every project.

Dependecies

Project uses ARC.

Project uses other libraries:

  • ASIHttpRequest
  • Nimbus
  • Reachability

All of them are loading with CocoaPods.

Using with CocoaPods

pod 'P34Utils', :git => 'https://github.com/pilot34/P34Utils.git'

This is not full documentation, it is only examples. All of methods you can find in header files.

Categories

UIView

Useful methods for coordinate access.

    UIView *view = [[UIView alloc] init];
    view.top = 10;
    view.left = 20;
    view.height = otherView.height + 10;
    view.origin = CGPointMake(20, 30);
    view.bottom = 30; // change top without changing height
    [view setBottom:30 changeHeight:YES]; // change height, withouth changing top

NSArray

Some sort of functional methods implementation (methods are not lazy):

    NSArray *arr = [@"a", @"aa", @"ab", @"abb"];

    NSArray *filtered = [arr where:^(id element){
        return [element length] > 1;
    }];

    NSArray *select = [arr select^(id element){
       return [NSString stringWithFormat:@"123%@123", element]; 
    }];

Loading from nib

    // loading view from MyView.xib
    MyView *view = [MyView fromNib]; 

    // loading controller from CustomViewController.xib
    CustomViewController *c = [CustomViewController fromNib]; 

    // loading reusable cell with identifier "CustomCell" or, if nil, cell from CustomCell.xib
    CustomCell *cell = [self.tableView cellFromNib:CustomCell.class];

Reachability

    // static checks without stupid API
    if ([Reachability isWiFiReachable])
    {
        ...
    }

    if ([Reachability isInternetReachable])
    {
        ...
    }

Fading transparency

Useful for fading scroll view. You should add UIScrollView to container UIView and add fading to container.

Warning! Fading don't layout correctly, so you should do addFading each time after resizing.

    UIView *container = ...;
    [container addFading:(FadingTypeTop | FadingTypeBottom) withSize:20];

Inheritors

There are many inheritors for classes from UIKit. Some examples.

BlockAlertView

    [BlockAlertView showTitle:nil
                         text:@"Message"
                 cancelButton:@"OK"
                       action:^{
                           // some action after user pressed OK
    }];

    [BlockAlertView showTitle:nil
                         text:@"Download this file?"
                 cancelButton:@"No"
                 submitButton:@"Yes"
                       action:^{
                           // some action if user pressed YES
    }];

BlockTapGestureRecognizer

    BlockTapGestureRecognizer *tap = [[BlockTapGestureRecognizer alloc] initWithAction:^{
        [self dismissModalViewControllerAnimated:YES];
    }];
    [self.view addGestureRecognizer:tap];

    // or you can do it simplier
    [self.view addTapAction:^{
        // do something
    }];

Other utils classes

VideoPlayingResolver

If you have UIWebView with html, after device rotation you should reload html for correct relayouting. If you have embedded video in HTML and layout during playing video, it will be stopped. So you shouldn't reload html during fullscreen video playing.

This class subscribing to needed notifications and you can check, reload html or not.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.playingResolver = [[VideoPlayingResolver alloc] init];
        self.playingResolver.delegate = self;
    }
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    
    if (!self.playingResolver.isPlaying)
        [self reloadHTML];
}

#pragma mark - VideoPlayingResolverDelegate

- (void)videoPlayingResolverDidFinishPlaying:(BOOL)wasRotation
{
    if (wasRotation)
        [self reloadHTML];
}

Macros and functions

doAfter(1, ^{
   // do something on this thread after 1 second with GCD
});


// doing this: weak wself = self
// using to avoid retain cycles
WSELF; 
[self addTapAction:{
   [wself doSomething]; 
}];

p34utils's People

Contributors

pilot34 avatar

Stargazers

Leonardo Cavalcante avatar George Ymydykov avatar  avatar Eugen avatar Telenkov Ivan avatar Max Sokolov avatar caiguo avatar  avatar mayulu avatar Vasily Anisimov avatar Pavel 'Pasha' Mazurin avatar Serhii Puliaiev avatar Dima Shmidt avatar Nikolai Iasnov avatar bright avatar Rinat avatar  avatar Valentine Silvansky avatar Maiorov Alexander avatar Eduard Panasiuk avatar Oleg Marko avatar Soniccat avatar Andy Chentsov avatar

Watchers

Sergey Buravtsov avatar mayulu avatar  avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.