AFNetworking
#import "UIKit+ afnetworking. h" #import "UIKit+ afnetworking. h" #import "UIKit+ afnetworking. hCopy the code
Basic usage format:
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; /** AFHTTPSessionManager Singleton object configuration */ Manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; / / said do not do the SSL pinning manager. ResponseSerializer = [AFJSONResponseSerializer serializer]; // Response type: Json type manager. ResponseSerializer. AcceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",@"text/heml", nil]; / / the type of support manager. RequestSerializer. TimeoutInterval = 6; [Manager GET:urlStr Parameters: Parameters progress:nil Success :^(NSURLSessionDataTask * _Nonnull Task, id _Nullable responseObject) { NSLog(@"JSON DATA: %@", responseObject); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"Error: %@", error); }];Copy the code
When reencapsulating, block can be used together! Reference: Block Use with Network Requests (AFNetworking).
Detailed reference: Introduction and Use of AFNetworking
Masonry
#import "Masonry.h"
Copy the code
Basic usage:
-
New constraint: – (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
[mas_makeConstraints:^(MASConstraintMaker *make) {// only make new constrains (does not exist with Autolayout)}];Copy the code
-
Clear constraint: – (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
[mas_updateConstraints:^(MASConstraintMaker *make) {// // clear all previous constraints, only the latest ones}];Copy the code
-
Update constraint: – (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
[mas_remakeConstraints:^(MASConstraintMaker *make) {// update a constraint that appears in a block so that two of the same constraints do not appear}];Copy the code
SDWebImage
#import <SDWebImage/UIButton+ webcache.h > #import <SDWebImage/UIButton+WebCacheCopy the code
Basic usage:
NSString * picUrlStr = @"http://www.domain.com/path/pics/blabla_1.jpg"; [_imgView sd_setImageWithURL:[NSURL URLWithString: picUrlStr] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; // placeholder image name: "placeholder"Copy the code
Detailed reference: iOS Image Loading Framework -SDWebImage Interpretation
Data parsing
-
YYModel
#import "YYModel.h" Copy the code
Basic usage:
Model class UserInfoLogModel
“UserInfoLogModel. H” definition:
@interface UserInfoLogModel: BaseModel // inherit from the BaseModel classCopy the code
BaseModel class BaseModel
#import "yyModel. h" @interface BaseModel: NSObject <YYModelCopy the code
Use of UserInfoLogModel:
NSDictionary * jsonDict = responseObject[@"DataList"]; / / the JSON data (NSData, nsstrings, NSDictionary) is converted into a Model UserInfoLogModel * userInfoModel = [UserInfoLogModel yy_modelWithJSON:jsonDict ];Copy the code
Demonstration examples 🌰
DetailsOfDiscussModel class: The Key value of JSON is different from the attribute name of the corresponding Model (change the Model attribute name corresponding to the Key of JSON); The Model attribute contains the container type.
DetailsOfDiscussModel. H:
#import "BaseModel.h" @interface DetailsOfDiscussModel : BaseModel @property (nonatomic,strong) NSString * content; @property (nonatomic,strong) NSString * _id; //⭐ ⭐ ⭐ to change the Model attribute name of the Key of JSON ⭐ ⭐ maximal maximal @property (nonatomic,copy) NSArray * members; //⭐ ⭐ ⭐ ⭐ ⭐ @property (nonatomic,strong) NSString * topic; // subject @end @interface DiscussMemberModel: basemodel@property (nonatomic,copy) NSString * avatar; // Avatar @property(nonatomic,copy) NSString * cityCode; @property(nonatomic,copy) NSString * cityName; @property(nonatomic,copy) NSString * countyCode; @property(nonatomic,copy) NSString * countyName; @property(nonatomic,copy) NSString * mobile; @property(nonatomic,copy) NSString * userId; // User id@property (nonatomic,copy) NSString * userName; // User name @endCopy the code
DetailsOfDiscussModel. M:
#import "detailsofdiscussmodel. h" @implementation DetailsOfDiscussModel // Return a Dict with the Model attribute name and Key mapped to JSON. + (NSDictionary *) modelCustomPropertyMapper {return @ {@ "_id" : @ "id" / / ⭐ ️ ⭐ ️ ⭐ ️ change JSON Key corresponding to the Model attribute name ⭐ ️ ⭐ ️ ⭐ ️}; } // Return a Dict, The Model name and Model attribute container need to store the object type + (NSDictionary *) modelContainerPropertyGenericClass {return @{@"members":[DiscussMemberModel class]}; //⭐ ⭐ ⭐ one container type ⭐ ⭐ ⭐} @end @implementation DiscussMemberModel // only implement @endCopy the code
Detailed reference: introduction and Use of YYModel
-
JSONModel
#import "JSONModel.h" Copy the code
Basic usage:
Model class UserInfoLogModel
“UserInfoLogModel. H” definition:
@interface UserInfoLogModel: JSONModel // inherited from the JSONModel classCopy the code
Use of UserInfoLogModel:
NSDictionary * jsonDict = responseObject[@"DataList"]; NSError* err = nil; UserInfoLogModel * userInfoModel = [[UserInfoLogModel alloc] initWithDictionary:jsonDict error:&err]; Copy the code
IQKeyboardManager
#import "IQKeyboardManager.h"
Copy the code
Basic usage:
//IQKeyboardManager singleton object IQKeyboardManager *manager = [IQKeyboardManager sharedManager]; // Disable the function by setting it to YES (default is NO) manager.enable = YES; / / click on the blank area contraction keyboard switch (the default value is NO) manager. ShouldResignOnTouchOutside = YES; / / display its own keyboard toolbar switch (the default value is YES) manager. EnableAutoToolbar = NO;Copy the code
When a particular input box (_editTF) do not need to use the bar on the keyboard: _editTF. InputAccessoryView = [[UIView alloc] init];
Events that need to disable automatic keyboard processing on a certain page:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[IQKeyboardManager sharedManager] setEnable:NO];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[IQKeyboardManager sharedManager] setEnable:YES];
}
Copy the code
MJRefresh
#import "MJRefresh.h"
Copy the code
Basic usage:
(mj_header, mj_footer)
Self. DiscussListTabV. Mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock: ^ {/ / update the drop-down (network request) [weakSelf getDataWith:10 and:0]; }]; Self. DiscussListTabV. Mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock: ^ {/ / pull refresh request (network) [weakSelf getDataWith:10 and:(int)self.dataArray.count]; }]; Self. discusslistTabv.mj_footer. hidden = NO; // Display "pull up refresh" (for the first time) self. discusslistTabv.mj_footer. hidden = NO; // Display "mj_footer" at the bottom (" pull-up refresh ")Copy the code
Hide and display the bottom “mj_footer” (” pull-up refresh “) :
// When you scroll up and down the tableView, Display (" refresh ") at the bottom of the "mj_footer" - (void) scrollViewWillBeginDragging judging: (scrollView UIScrollView *) {/ / "request to the data already?? To set display or not! self.discussListTabV.mj_footer.hidden = NO; // Display the "mj_footer" at the bottom of (" pull up refresh ")}Copy the code
Dispatch_async (dispatch_get_main_queue(), ^{// Stop refreshing [self. discusslistTabv. mj_header endRefreshing]; [self.discussListTabV.mj_footer endRefreshing]; self.discussListTabV.mj_footer.hidden = YES; // Hide the "mj_footer" at the bottom (" pull up refresh ")});Copy the code
Dispatch_async (dispatch_get_main_queue(), ^{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeText; hud.label.text = [error localizedDescription]; Hud. Margin = 10.f; hud.offset = CGPointMake(0, 0.f); hud.removeFromSuperViewOnHide = YES; [hud hideAnimated: YES afterDelay: 1.5 f]; hud.userInteractionEnabled = NO; self.discussListTabV.mj_footer.hidden = NO; // Display the "mj_footer" at the bottom (" pull up refresh ")});Copy the code
Progress indicator (Daisy turn)
-
SVProgressHUD
Basic usage:
+ (void)setBackgroundColor:(UIColor*)color; // Background color (default: white) + (void)setForegroundColor:(UIColor*)color; // Remember to render the image!! + (void)setInfoImage:(UIImage*)image; + (void)setSuccessImage:(UIImage*)image; // successful image + (void)setErrorImage:(UIImage*)image; + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; / / HUD display mode / * * SVProgressHUDMaskTypeNone = 1, / / allow the user to perform other SVProgressHUDMaskTypeClear operation, / / do not allow the user to other operating SVProgressHUDMaskTypeBlack, / / do not allow the user to other operations, and the background to black SVProgressHUDMaskTypeGradient / / allow the user to perform other operations, * / + (void)show; + (void)showWithStatus:(NSString*)status; + (void)setStatus:(NSString*)string; // change the text being displayed on the HUD + (void)showProgress:(float)progress; // Show progress box: a progress circle + (void)showImage:(UIImage*)image status:(NSString*)status; // Show the image I set (image size: 28px * 28px) + (void)dismiss; + (void)setOffsetFromCenter:(UIOffset)offset; // The offset from the center + (void)resetOffsetFromCenter; // return center point + (void)showSuccessWithStatus:(NSString*)string; + (void)showErrorWithStatus:(NSString *)string; // Display error message + (BOOL)isVisible; // Monitor: whether it is showingCopy the code
Delay stop “chrysanthemum rotation”
Delay 0.6s, execute stop method!
[SVProgressHUD showWithStatus: NSLocaString (@ "loading...")]; [self performSelector:@selector(progressDelayDismiss) withObject:nil afterDelay:0.6f]; -(void)progressDelayDismiss {// Stop "activity indicator" [SVProgressHUD dismiss]; }Copy the code
Hide the “SVProgressHUD” singleton class with a GCD delay of 0.6s!
/ / SVProgressHUD offset [SVProgressHUD setOffsetFromCenter: UIOffsetMake (0, 0)]; [SVProgressHUD showWithStatus: NSLocaString (@ "loading...")]; Dispatch_after (dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6f * NSEC_PER_SEC)), ^{// Fade after 0.6 seconds [SVProgressHUD dismiss]; });Copy the code
-
MBProgressHUD
Basic usage:
-
Display text only:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; // Define and load the view to hud. Mode = MBProgressHUDModeText; // Mode: display text hud. Label. text = @" Cannot dial!" ; Hud. Margin = 10.f; Hud. Offset = CGPointMake(0, 0.f); / / hud offset hud. RemoveFromSuperViewOnHide = YES; [hud hideAnimated: YES afterDelay: 1.5 f]; / / 1.5 s backwards away with hud hud. UserInteractionEnabled = NO. // During hud display, the parent view is not available for user interaction!Copy the code
-
Load animation: Rotate the load circle
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeCustomView; / / custom views UIImage * image = [[UIImage imageNamed: @ "01"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]; UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@" transform.Rotation "]; anima.toValue = @(M_PI*2); Anima. Duration = 1.0 f; anima.repeatCount = 10; [imgView.layer addAnimation:anima forKey:nil]; //layer Animation hud. CustomView = imgView; Hud. Mode = MBProgressHUDModeText; Hud. Label. text = @" loading..." ; hud.margin = 10.f; hud.offset = CGPointMake(0, -100.f); hud.removeFromSuperViewOnHide = YES; [hud hideAnimated: YES afterDelay: 1.5 f]; // Display cycleCopy the code
For more, see Source notes –MBProgressHUD
SDCycleScrollView
#import < sdcyclesCrollView. hCopy the code
SKPSMTPMessage
CocoaPods import: pod ‘skpsmtpMessage’ #
#import "NSData+Base64Additions. H "// EmailCopy the code
Reference: “Tripartite library” : the introduction of all kinds of tripartite library! “CocoaPods” : CocoaPods is introduced and using the CocoaPods import third-party libraries commonly used: using CocoaPods import tripartite library “tripartite library mistake” : the three parties used by the library and solve the problem
The article continues to be updated in the ~~ summary of the article all separate, in order to summarize!
(2017.12.04)
goyohol’s essay