📜 ⬆️ ⬇️

iOS Developer Tools

Introduction


Hello everyone, my name is Gregory, the last 5 years I have been programming under iOS. Now I decided to change the scope of activities and hit the web, but so that the good would not disappear, I want to share with the community my own achievements that have accumulated during this time. Libraries are posted on GitHub and added to CocoaPods. Instructions for installation and use you can find on the links on GitHub, here is a brief description.

The minimum supported version is iOS 6.0.

LGAlertView


Screenshots


UIAlertView is one of the frequently used components when developing on iOS. It looks and works out of the box remarkably, the problem is that Apple practically does not give any opportunities to customize it, there are only a few standardly defined display styles. But what if we need to insert our view inside, or is it trivial to change the color of the buttons or the background? So it was decided to write a universal class that would repeat the work of UIAlertView, but had ample opportunities for customization. This is how the LGAlertView came about.

When initializing, we have a choice between several styles:
')
Some code
Standard (header + message + buttons):
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 

With built-in view (header + message + UIView + buttons):
 - (instancetype)initWithViewStyleWithTitle:(NSString *)title message:(NSString *)message view:(UIView *)view buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 

With an activity indicator (header + message + UIActivityIndicatorView + buttons):
 - (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title message:(NSString *)message buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 

With progress bar (header + message + UIProgressView + buttons):
 - (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title message:(NSString *)message buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 

With input fields (header + message + input fields + buttons):
 - (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title message:(NSString *)message buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 


To be able to catch events there are several ways: delegation, as in the standard UIAlertView, and blocks (as you like). In addition, NSNotification is provided for the appearance and disappearance of LGAlertView from the screen. At first I thought of adding notifications for buttons, but I decided that it would still be superfluous.

Some code
Delegation:

 @property (assign, nonatomic) id<LGAlertViewDelegate> delegate; - (void)alertViewWillShow:(LGAlertView *)alertView; - (void)alertViewWillDismiss:(LGAlertView *)alertView; - (void)alertViewDidShow:(LGAlertView *)alertView; - (void)alertViewDidDismiss:(LGAlertView *)alertView; - (void)alertView:(LGAlertView *)alertView buttonPressedWithTitle:(NSString *)title index:(NSUInteger)index; - (void)alertViewCancelled:(LGAlertView *)alertView; - (void)alertViewDestructiveButtonPressed:(LGAlertView *)alertView; 

Blocks:
 @property (strong, nonatomic) void (^willShowHandler)(LGAlertView *alertView); @property (strong, nonatomic) void (^willDismissHandler)(LGAlertView *alertView); @property (strong, nonatomic) void (^didShowHandler)(LGAlertView *alertView); @property (strong, nonatomic) void (^didDismissHandler)(LGAlertView *alertView); @property (strong, nonatomic) void (^actionHandler)(LGAlertView *alertView, NSString *title, NSUInteger index); @property (strong, nonatomic) void (^cancelHandler)(LGAlertView *alertView, BOOL onButton); @property (strong, nonatomic) void (^destructiveHandler)(LGAlertView *alertView); 

NSNotifications:

 kLGAlertViewWillShowNotification; kLGAlertViewWillDismissNotification; kLGAlertViewDidShowNotification; kLGAlertViewDidDismissNotification; 


To customize the appearance there are many properties. To list them for a long time, I think everything should be clear from the titles:

Some code
 /** Default is YES */ @property (assign, nonatomic, getter=isCancelOnTouch) BOOL cancelOnTouch; /** Set highlighted buttons background color to blue, and set highlighted destructive button background color to red. Default is YES */ @property (assign, nonatomic, getter=isColorful) BOOL colorful; @property (strong, nonatomic) UIColor *tintColor; @property (strong, nonatomic) UIColor *coverColor; @property (strong, nonatomic) UIColor *backgroundColor; @property (assign, nonatomic) CGFloat layerCornerRadius; @property (strong, nonatomic) UIColor *layerBorderColor; @property (assign, nonatomic) CGFloat layerBorderWidth; @property (strong, nonatomic) UIColor *layerShadowColor; @property (assign, nonatomic) CGFloat layerShadowRadius; @property (assign, nonatomic) CGFloat heightMax; @property (assign, nonatomic) CGFloat widthMax; @property (strong, nonatomic) UIColor *titleTextColor; @property (assign, nonatomic) NSTextAlignment titleTextAlignment; @property (strong, nonatomic) UIFont *titleFont; @property (strong, nonatomic) UIColor *messageTextColor; @property (assign, nonatomic) NSTextAlignment messageTextAlignment; @property (strong, nonatomic) UIFont *messageFont; @property (strong, nonatomic) UIColor *buttonsTitleColor; @property (strong, nonatomic) UIColor *buttonsTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment buttonsTextAlignment; @property (strong, nonatomic) UIFont *buttonsFont; @property (strong, nonatomic) UIColor *buttonsBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger buttonsNumberOfLines; @property (assign, nonatomic) NSLineBreakMode buttonsLineBreakMode; @property (assign, nonatomic) BOOL buttonsAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat buttonsMinimumScaleFactor; @property (strong, nonatomic) UIColor *cancelButtonTitleColor; @property (strong, nonatomic) UIColor *cancelButtonTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment cancelButtonTextAlignment; @property (strong, nonatomic) UIFont *cancelButtonFont; @property (strong, nonatomic) UIColor *cancelButtonBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger cancelButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode cancelButtonLineBreakMode; @property (assign, nonatomic) BOOL cancelButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat cancelButtonMinimumScaleFactor; @property (strong, nonatomic) UIColor *destructiveButtonTitleColor; @property (strong, nonatomic) UIColor *destructiveButtonTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment destructiveButtonTextAlignment; @property (strong, nonatomic) UIFont *destructiveButtonFont; @property (strong, nonatomic) UIColor *destructiveButtonBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger destructiveButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode destructiveButtonLineBreakMode; @property (assign, nonatomic) BOOL destructiveButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat destructiveButtonMinimumScaleFactor; @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (strong, nonatomic) UIColor *activityIndicatorViewColor; @property (strong, nonatomic) UIColor *progressViewProgressTintColor; @property (strong, nonatomic) UIColor *progressViewTrackTintColor; @property (strong, nonatomic) UIImage *progressViewProgressImage; @property (strong, nonatomic) UIImage *progressViewTrackImage; @property (strong, nonatomic) UIColor *progressLabelTextColor; @property (assign, nonatomic) NSTextAlignment progressLabelTextAlignment; @property (strong, nonatomic) UIFont *progressLabelFont; @property (strong, nonatomic) UIColor *separatorsColor; @property (assign, nonatomic) UIScrollViewIndicatorStyle indicatorStyle; 


To show or hide the LGAlertView, the following methods are provided:
 - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)dismissAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; 

In addition, it was possible to achieve the correct behavior in the case when several views appear in a row without closing the previous ones. You can easily combine UIAlertView, UIActionSheet, LGAlertView and LGActionSheet. When new ones appear, the old ones will disappear, and when they disappear, they will appear.

LGActionSheet


Screenshots


The causes and the principle of operation are similar to LGAlertView.

Styles at initialization:

Some code
Standard (message + buttons):
 - (instancetype)initWithTitle:(NSString *)title buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 

With built-in view (message + UIView + buttons):
 - (instancetype)initWithTitle:(NSString *)title view:(UIView *)view buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; 


Events are captured using delegations, blocks and notifications:

Some code
Delegation:

 @property (assign, nonatomic) id<LGActionSheetDelegate> delegate; - (void)actionSheetWillShow:(LGActionSheet *)actionSheet; - (void)actionSheetWillDismiss:(LGActionSheet *)actionSheet; - (void)actionSheetDidShow:(LGActionSheet *)actionSheet; - (void)actionSheetDidDismiss:(LGActionSheet *)actionSheet; - (void)actionSheet:(LGActionSheet *)actionSheet buttonPressedWithTitle:(NSString *)title index:(NSUInteger)index; - (void)actionSheetCancelled:(LGActionSheet *)actionSheet; - (void)actionSheetDestructiveButtonPressed:(LGActionSheet *)actionSheet; 

Blocks:

 @property (strong, nonatomic) void (^willShowHandler)(LGActionSheet *actionSheet); @property (strong, nonatomic) void (^willDismissHandler)(LGActionSheet *actionSheet); @property (strong, nonatomic) void (^didShowHandler)(LGActionSheet *actionSheet); @property (strong, nonatomic) void (^didDismissHandler)(LGActionSheet *actionSheet); @property (strong, nonatomic) void (^actionHandler)(LGActionSheet *actionSheet, NSString *title, NSUInteger index); @property (strong, nonatomic) void (^cancelHandler)(LGActionSheet *actionSheet, BOOL onButton); @property (strong, nonatomic) void (^destructiveHandler)(LGActionSheet *actionSheet); 

NSNotifications:

 kLGActionSheetWillShowNotification; kLGActionSheetWillDismissNotification; kLGActionSheetDidShowNotification; kLGActionSheetDidDismissNotification; 


Customize appearance and animations (default animations for iPhone and iPad differ):

Some code
 @property (assign, nonatomic) LGActionSheetTransitionStyle transitionStyle; /** Default is YES */ @property (assign, nonatomic, getter=isCancelOnTouch) BOOL cancelOnTouch; /** Set highlighted buttons background color to blue, and set highlighted destructive button background color to red. Default is YES */ @property (assign, nonatomic, getter=isColorful) BOOL colorful; @property (strong, nonatomic) UIColor *tintColor; @property (strong, nonatomic) UIColor *coverColor; @property (strong, nonatomic) UIColor *backgroundColor; @property (assign, nonatomic) CGFloat layerCornerRadius; @property (strong, nonatomic) UIColor *layerBorderColor; @property (assign, nonatomic) CGFloat layerBorderWidth; @property (strong, nonatomic) UIColor *layerShadowColor; @property (assign, nonatomic) CGFloat layerShadowRadius; @property (assign, nonatomic) CGFloat heightMax; @property (assign, nonatomic) CGFloat widthMax; @property (strong, nonatomic) UIColor *titleTextColor; @property (assign, nonatomic) NSTextAlignment titleTextAlignment; @property (strong, nonatomic) UIFont *titleFont; @property (strong, nonatomic) UIColor *buttonsTitleColor; @property (strong, nonatomic) UIColor *buttonsTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment buttonsTextAlignment; @property (strong, nonatomic) UIFont *buttonsFont; @property (strong, nonatomic) UIColor *buttonsBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger buttonsNumberOfLines; @property (assign, nonatomic) NSLineBreakMode buttonsLineBreakMode; @property (assign, nonatomic) BOOL buttonsAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat buttonsMinimumScaleFactor; @property (strong, nonatomic) UIColor *cancelButtonTitleColor; @property (strong, nonatomic) UIColor *cancelButtonTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment cancelButtonTextAlignment; @property (strong, nonatomic) UIFont *cancelButtonFont; @property (strong, nonatomic) UIColor *cancelButtonBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger cancelButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode cancelButtonLineBreakMode; @property (assign, nonatomic) BOOL cancelButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat cancelButtonMinimumScaleFactor; @property (strong, nonatomic) UIColor *destructiveButtonTitleColor; @property (strong, nonatomic) UIColor *destructiveButtonTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment destructiveButtonTextAlignment; @property (strong, nonatomic) UIFont *destructiveButtonFont; @property (strong, nonatomic) UIColor *destructiveButtonBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger destructiveButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode destructiveButtonLineBreakMode; @property (assign, nonatomic) BOOL destructiveButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat destructiveButtonMinimumScaleFactor; @property (strong, nonatomic) UIColor *separatorsColor; @property (assign, nonatomic) UIScrollViewIndicatorStyle indicatorStyle; 


To show or hide the LGActionSheet the following methods are provided:
 - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)dismissAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; 


LGSideMenuController


Screenshots


Nowadays, almost no serious application can do without leaving side menus. At some point, tired of writing one-off solutions for each project and this library was created.

Short list of features:

Adding this controller to the project is quite simple. You need to specify your root controller (usually UINavigationController) as the LGSideMenuController root controller ... it sounds a bit tautological, I will give an example:

Normal initialization of the root controller in AppDelegate.m:

 ViewController *viewController = [ViewController new]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; window.rootViewController = navigationController; 

Initialization with LGSideMenuController:

 ViewController *viewController = [ViewController new]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; LGSideMenuController *sideMenuController = [[LGSideMenuController alloc] initWithRootViewController:navigationController]; window.rootViewController = sideMenuController; 

Adjusting the side menus is also not difficult. First you need to include the menus that you need (left, right, or both):

 [sideMenuController setLeftViewEnabledWithWidth:250.f //    presentationStyle:LGSideMenuPresentationStyleScaleFromBig //   alwaysVisibleOptions:0]; //   

Next, add your views, which will be shown in the side menu:

 TableViewController *leftViewController = [TableViewController new]; [sideMenuController.leftView addSubview:leftViewController.tableView]; 

To show or hide side menus, the following methods are provided:

 - (void)showLeftViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)hideLeftViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showHideLeftViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)hideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showHideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; 

The following NSNotifications are also present:

 kLGSideMenuControllerWillShowLeftViewNotification; kLGSideMenuControllerWillDismissLeftViewNotification; kLGSideMenuControllerDidShowLeftViewNotification; kLGSideMenuControllerDidDismissLeftViewNotification; kLGSideMenuControllerWillShowRightViewNotification; kLGSideMenuControllerWillDismissRightViewNotification; kLGSideMenuControllerDidShowRightViewNotification; kLGSideMenuControllerDidDismissRightViewNotification; 

LGPlusButtonsView


Screenshots


Google has recently been actively promoting its Material Design, one of the components of which is the "+" button, which causes some additional options. The solution is quite interesting. In my practice, there was a customer who requested this functionality to be implemented on iOS. Therefore, the rubber did not and immediately decided to write a universal solution.

Short list of features:

Initialization:

 - (instancetype)initWithView:(UIView *)view numberOfButtons:(NSUInteger)numberOfButtons showsPlusButton:(BOOL)showsPlusButton; 

Events are captured using delegation or blocks:

Some code
Delegation:

 @property (assign, nonatomic) id<LGPlusButtonsViewDelegate> delegate; - (void)plusButtonsView:(LGPlusButtonsView *)plusButtonsView buttonPressedWithTitle:(NSString *)title description:(NSString *)description index:(NSUInteger)index; - (void)plusButtonsViewPlusButtonPressed:(LGPlusButtonsView *)plusButtonsView; 

Blocks:

 @property (strong, nonatomic) void (^actionHandler)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index); @property (strong, nonatomic) void (^plusButtonActionHandler)(LGPlusButtonsView *plusButtonView); 


Customize the appearance and animations:

Some code
 @property (assign, nonatomic, getter=isShowWhenScrolling) BOOL showWhenScrolling; @property (strong, nonatomic) LGPlusButton *plusButton; /** First is plusButton */ @property (strong, nonatomic) NSMutableArray *buttons; /** First is plusButton description */ @property (strong, nonatomic) NSMutableArray *descriptions; @property (assign, nonatomic) UIEdgeInsets contentInset; @property (assign, nonatomic) UIEdgeInsets buttonInset; @property (assign, nonatomic) CGSize buttonsSize; @property (assign, nonatomic) CGSize plusButtonSize; /** Description horizontal offset from button, default is 6.f */ @property (assign, nonatomic) CGFloat descriptionOffsetX; @property (assign, nonatomic) LGPlusButtonsAppearingAnimationType appearingAnimationType; @property (assign, nonatomic) LGPlusButtonsAppearingAnimationType buttonsAppearingAnimationType; @property (assign, nonatomic) LGPlusButtonAnimationType plusButtonAnimationType; @property (assign, nonatomic) LGPlusButtonsViewPosition position; - (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state; - (void)setButtonsTitleColor:(UIColor *)titleColor forState:(UIControlState)state; - (void)setButtonsImage:(UIImage *)image forState:(UIControlState)state; - (void)setButtonsBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state; - (void)setButtonsBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; - (void)setButtonsTitleFont:(UIFont *)font; - (void)setDescriptionsTexts:(NSArray *)texts; - (void)setDescriptionsTextColor:(UIColor *)textColor; - (void)setDescriptionsBackgroundColor:(UIColor *)backgroundColor; - (void)setDescriptionsFont:(UIFont *)font; - (void)setButtonsClipsToBounds:(BOOL)clipsToBounds; - (void)setButtonsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets; - (void)setButtonsAdjustsImageWhenHighlighted:(BOOL)adjustsImageWhenHighlighted; - (void)setButtonsLayerMasksToBounds:(BOOL)masksToBounds; - (void)setButtonsLayerCornerRadius:(CGFloat)cornerRadius; - (void)setButtonsLayerBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth; - (void)setButtonsLayerShadowColor:(UIColor *)shadowColor shadowOpacity:(float)shadowOpacity shadowOffset:(CGSize)shadowOffset shadowRadius:(CGFloat)shadowRadius; 


To show or hide the LGPlusButtonsView, the following methods are provided:

 //   ,   "+" - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)hideAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; //    - (void)showButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)hideButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; 


LGFilterView


Screenshots


Quite often, in news applications, you have to make filters, for example, to select a category of output materials. Their logic is quite similar, usually this is a drop-down table with names. This functionality and implements LGFilterView.

Short list of features:

You can initialize either with a list of possible names (then the filter will look like a table), or with your custom view (which the filter will show):

 - (instancetype)initWithView:(UIView *)view; - (instancetype)initWithTitles:(NSArray *)titles; 

Events are captured using delegations, blocks and notifications:

Some code
Delegation:
 @property (assign, nonatomic) id<LGFilterViewDelegate> delegate; - (void)filterViewWillShow:(LGFilterView *)filterView; - (void)filterViewWillDismiss:(LGFilterView *)filterView; - (void)filterViewDidShow:(LGFilterView *)filterView; - (void)filterViewDidDismiss:(LGFilterView *)filterView; - (void)filterView:(LGFilterView *)filterView buttonPressedWithTitle:(NSString *)title index:(NSUInteger)index; - (void)filterViewCancelled:(LGFilterView *)filterView; 

Blocks:

 @property (strong, nonatomic) void (^willShowHandler)(LGFilterView *filterView); @property (strong, nonatomic) void (^willDismissHandler)(LGFilterView *filterView); @property (strong, nonatomic) void (^didShowHandler)(LGFilterView *filterView); @property (strong, nonatomic) void (^didDismissHandler)(LGFilterView *filterView); @property (strong, nonatomic) void (^actionHandler)(LGFilterView *filterView, NSString *title, NSUInteger index); @property (strong, nonatomic) void (^cancelHandler)(LGFilterView *filterView); 

NSNotifications:

 kLGFilterViewWillShowNotification; kLGFilterViewWillDismissNotification; kLGFilterViewDidShowNotification; kLGFilterViewDidDismissNotification; 


Customize appearance and animations (default animations for iPhone and iPad differ):

Some code
 @property (assign, nonatomic) LGFilterViewTransitionStyle transitionStyle; @property (assign, nonatomic) CGPoint offset; @property (assign, nonatomic) UIEdgeInsets contentInset; @property (assign, nonatomic) CGFloat heightMax; @property (assign, nonatomic, getter=isSeparatorsVisible) BOOL separatorsVisible; @property (strong, nonatomic) UIColor *separatorsColor; @property (assign, nonatomic) UIEdgeInsets separatorsEdgeInsets; @property (strong, nonatomic) UIColor *titleColor; @property (strong, nonatomic) UIColor *titleColorHighlighted; @property (strong, nonatomic) UIColor *titleColorSelected; @property (strong, nonatomic) UIColor *backgroundColorHighlighted; @property (strong, nonatomic) UIColor *backgroundColorSelected; @property (strong, nonatomic) UIFont *font; @property (assign, nonatomic) NSUInteger numberOfLines; @property (assign, nonatomic) NSLineBreakMode lineBreakMode; @property (assign, nonatomic) NSTextAlignment textAlignment; @property (assign, nonatomic) BOOL adjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat minimumScaleFactor; @property (assign, nonatomic) CGFloat cornerRadius; @property (assign, nonatomic) CGFloat borderWidth; @property (strong, nonatomic) UIColor *borderColor; @property (assign, nonatomic) UIScrollViewIndicatorStyle indicatorStyle; 


The following methods are provided to show or hide the filter:

 - (void)showInView:(UIView *)view animated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)dismissAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; 


LGRefreshView


Screenshots


“Pull to update” is a very fashionable feature that exists in almost every application. Even Apple could not resist and in iOS 6 added this functionality, but for some reason only for UITableView, and UICollectionView and UIScrollView were left behind. Although with the help of some crutches, a standard “pull to refresh” can be screwed for the UICollectionView, but we do not need crutches. To tell the truth, various “refreshments” are full on the githaba, he himself has been looking for a suitable one for a long time, but mostly there are either abandoned popular old versions that have accumulated a bunch of different problems, or very cool libraries that do unimaginable things, but are too sophisticated in design, to be able to use them in any project. Therefore, I decided to try to make a universal, customizable and neutral “pull to refresh”.

During initialization, you need to specify the parent view, which should be a UIScrollView or an inherited class (UITableView or UICollectionView. The idea should work with UIWebView, but there were problems during the tests, therefore I do not advise).

 - (instancetype)initWithScrollView:(UIScrollView *)scrollView; 

The refresh event is caught using delegation, blocks and notifications:

Some code
Delegation:

 @property (assign, nonatomic) id<LGRefreshViewDelegate> delegate; - (void)refreshViewRefreshing:(LGRefreshView *)refreshView; 

Blocks:

 @property (strong, nonatomic) void (^refreshHandler)(LGRefreshView *refreshView); 

NSNotifications:

 kLGRefreshViewBeginRefreshingNotification; kLGRefreshViewEndRefreshingNotification; 


To complete the update method is provided:

 - (void)endRefreshing; 

You can also call Refresh programmatically:

 - (void)triggerAnimated:(BOOL)animated; 


LGPlaceholderView


Screenshots


If you have a client-server application, then when switching to a new controller, you often have to download data. In order not to freeze the UI, this should be done in an additional stream. But what to show to the user while loading occurs? And you can show different things, for this purpose LGPlaceholderView is made.

What LGPlaceholderView can show:

In addition, the LGPlaceholderView will always be on top of other views. You can upload data, prepare it for display, and then animate the LGPlaceholderView.

When initializing, you need to specify a view that you will hide:

 - (instancetype)initWithView:(UIView *)view; 

Events can be caught with the help of notifications:

 kLGPlaceholderViewWillShowNotification; kLGPlaceholderViewWillDismissNotification; kLGPlaceholderViewDidShowNotification; kLGPlaceholderViewDidDismissNotification; 

There are various methods for the show, depending on what style you want to set:

 - (void)showActivityIndicatorAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showActivityIndicatorWithText:(NSString *)text animated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showProgressViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showProgressViewWithText:(NSString *)text animated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showText:(NSString *)text animated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showView:(UIView *)view animated:(BOOL)animated completionHandler:(void(^)())completionHandler; 

To hide the placeholder, you need to call:

 - (void)dismissAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; 

In addition, different styles can be combined, if you call several "show" methods in a row, the LGPlaceholderView will change to another.

LGDrawer




The programmatic drawing of images has long stirred my mind. Bitmap images are slowly dying off, even apple in the latest versions of xcode added support for vector images. But what if you do not burden the application with additional resources, and draw images right inside, the benefit of the tools allow.

The advantages of this approach, see me:

This is how LGDrawer appeared. Let's see what he can draw at the moment:

Some code
 #pragma mark - Rectangle + (UIImage *)drawRectangleWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees roundedCorners:(UIRectCorner)roundedCorners cornerRadius:(CGFloat)cornerRadius backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash strokeType:(LGDrawerStrokeType)strokeType shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Ellipse + (UIImage *)drawEllipseWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash strokeType:(LGDrawerStrokeType)strokeType shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Triangle /** Stroke type is center */ + (UIImage *)drawTriangleWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees cornerRadius:(CGFloat)cornerRadius direction:(LGDrawerDirection)direction backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Shadow + (UIImage *)drawShadowWithImageSize:(CGSize)imageSize direction:(LGDrawerDirection)direction backgroundColor:(UIColor *)backgroundColor shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Plus + (UIImage *)drawPlusWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness roundedCorners:(UIRectCorner)roundedCorners cornerRadius:(CGFloat)cornerRadius backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash strokeType:(LGDrawerStrokeType)strokeType shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; + (UIImage *)drawPlusWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness backgroundColor:(UIColor *)backgroundColor color:(UIColor *)color dash:(NSArray *)dash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Cross + (UIImage *)drawCrossWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness roundedCorners:(UIRectCorner)roundedCorners cornerRadius:(CGFloat)cornerRadius backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash strokeType:(LGDrawerStrokeType)strokeType shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; + (UIImage *)drawCrossWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness backgroundColor:(UIColor *)backgroundColor color:(UIColor *)color dash:(NSArray *)dash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Line + (UIImage *)drawLineWithImageSize:(CGSize)imageSize length:(CGFloat)length offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness direction:(LGDrawerLineDirection)direction backgroundColor:(UIColor *)backgroundColor color:(UIColor *)color dash:(NSArray *)dash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Tick + (UIImage *)drawTickWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness backgroundColor:(UIColor *)backgroundColor color:(UIColor *)color dash:(NSArray *)dash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Arrow + (UIImage *)drawArrowWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness direction:(LGDrawerDirection)direction backgroundColor:(UIColor *)backgroundColor color:(UIColor *)color dash:(NSArray *)dash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; + (UIImage *)drawArrowTailedWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness direction:(LGDrawerDirection)direction backgroundColor:(UIColor *)backgroundColor color:(UIColor *)color dash:(NSArray *)dash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Heart /** Stroke type is center */ + (UIImage *)drawHeartWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Star /** Stroke type is center */ + (UIImage *)drawStarWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Menu + (UIImage *)drawMenuWithImageSize:(CGSize)imageSize size:(CGSize)size offset:(CGPoint)offset rotate:(CGFloat)degrees thickness:(CGFloat)thickness dotted:(BOOL)dotted dotsPosition:(LGDrawerMenuDotsPosition)dotsPosition dotsCornerRadius:(CGFloat)dotsCornerRadius linesCornerRadius:(CGFloat)linesCornerRadius backgroundColor:(UIColor *)backgroundColor fillColor:(UIColor *)fillColor strokeColor:(UIColor *)strokeColor strokeThickness:(CGFloat)strokeThickness strokeDash:(NSArray *)strokeDash shadowColor:(UIColor *)shadowColor shadowOffset:(CGPoint)shadowOffset shadowBlur:(CGFloat)shadowBlur; #pragma mark - Images + (UIImage *)drawImage:(UIImage *)image1 onImage:(UIImage *)image2 clear:(BOOL)clear; + (UIImage *)drawImageOnImage:(NSArray *)images; + (UIImage *)drawImagesWithFinishSize:(CGSize)finishSize image1:(UIImage *)image1 image1Rect:(CGRect)rect1 image2:(UIImage *)image2 image2Rect:(CGRect)rect2 clear:(BOOL)clear; + (UIImage *)drawImagesWithFinishSize:(CGSize)finishSize image1:(UIImage *)image1 image1Offset:(CGPoint)offset1 image2:(UIImage *)image2 image2Offset:(CGPoint)offset2 clear:(BOOL)clear; 


The principle of drawing is as follows. Each method has parameters where you can set the size of the area (canvas) in which the image will be located, its fill; the size of the image itself, its fill, stroke, shadow, offset relative to the center inside the canvas, the angle of rotation of the image and, if possible, the thickness of the lines and the corners.
Not all parameters could be implemented for each method, but tried to the maximum possible.

It would be very interesting if the community helped expand the capabilities of this library. First, add the missing parameters where I could not. Secondly, increase the catalog of possible images.

LGViews


Screenshots


Often you want to expand the functionality of a particular view. Why can't I set contentEdgeInsets for UILabel? If I want to place UILabel over the picture, then for the convenience of reading the text, instead of expanding the background, I have to create an additional UIView. Or for UIButton, why you can set text for each state, text colors, a picture, a background image, but you cannot set a banal background color. What about choosing the location of the picture relative to the text?

In general, I think you understand the direction of my thoughts, in this library I wrote classes that extend the capabilities of standard views:

LGViewControllers


The same is true of UIViewControllers. But then expanding the possibilities was more difficult and not so obvious, so I do not think that I was able to fully achieve the desired result.

Short list:

LGHelper , LGHelper+NS , LGHelper+UI


Every day we solve a huge number of repetitive tasks. We remember most of them, but often small details of implementation are slipping away and we have to periodically refresh them in memory. These helpers are libraries that contain all kinds of macros and methods that help in everyday life. I have collected quite a lot of useful information here, it is not even necessary to use them in my projects, sometimes it is useful to just have a look in order to remember this or that feature.

Image processing, color conversion, use of masks, sending emails, calling a call with and without confirmation, showing a location on a map, finding out the status of an Internet connection, adding a person to the address book, encrypting data, receiving MD5 and SHA1 hashes, adding an event to the calendar , get the image from the camera ... and much more that I will not list here. I think the names of all methods and variables should be more or less intuitive, therefore, to get acquainted with the full list of features, I suggest viewing the header source files.

LGSharing , LGAudioStreamHelper , LGConnection


These 3 libraries, in my opinion, are not as interesting as the others. LGSharing, of course, helps to post to social networks (VKontakte, Facebook and Twitter) + send messages by email and sms. LGConnection is a wrapper around AFNetworking, out of the box can parse the response from the server including XML format + has the logic to handle the interruption of the Internet connection. LGAudioStreamHelper helps to work with audio streams, determine the format, receive metadata and record stream. I will not tell you in more detail if anyone is interested, go to the githab and try.



Thank you all for your attention.I would be very happy if my work will benefit someone. Open to objective criticism, suggestions for improving or expanding the functionality of libraries. If you have any questions - ask, I will try to answer.

Source: https://habr.com/ru/post/262615/


All Articles