SeaseAssist 0.0.93

SeaseAssist 0.0.93

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2020年10月

Logan Sease维护。



  • 作者
  • Logan Sease

SeaseAssist

[![CI状态](http://img.shields.io/travis/Logan Sease/SeaseAssist.svg?style=flat)](https://travis-ci.org/Logan Sease/SeaseAssist) 版本 许可证 平台

概要信息

此库基于这样一个理念:通常执行的任务,需要几行代码才能编写的,应封装到简单的方法中,无论是使用类扩展或服务,都可以用一行代码编写。因此减少了代码冗余,并增加了代码的可读性。

在这个包中,您将找到以下内容

  • 一组NSDate实用工具
  • 按钮和视图帮助工具,可以轻松制作出有吸引力的视图,并处理圆角、边框等问题
  • Array和Dictionary的扩展,用于转换为JSON和从JSON转换
  • 一个HTTP请求类,可以轻松发送api请求,无需任何非标准库
  • 一个UIImage View扩展,可以从URL加载图片并本地缓存图片。
  • NSString的验证帮助类
  • 字符串和NSData加密帮助工具
  • NSThread帮助工具,可以轻松在主线程和后台线程中运行代码块
  • 一个语音服务,用于语音到文本。
  • UIAlertController帮助工具,可以用于显示带有操作和文本输入的视图
  • 图像助手,用于模糊和调整大小等操作
  • 动画和动态效果助手
  • 一个视图控制器助手,可以递归地确定应用中的任何位置的可视视图控制器
  • 一个新的助手,可以在屏幕上显示文本,类似于Android的"Toast",并短时间显示
  • 网络可达性助手
  • 事件计数器,用来跟踪一个事件在整个应用生命周期或每天发生的次数
  • 模糊背景助手,可以在另一个视图之上呈现视图并模糊背景
  • 键盘助手,用于添加操作工具栏并在点击时隐藏键盘
  • 日期和值输入的TextField子类
  • 一个服务,可以帮助您轻松地在任何地方发送电子邮件
  • 还有更多功能!

享受!请随意fork并为此仓库做出贡献!

需求

ios 7+

安装

SeaseAssist通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中

pod "SeaseAssist"

并导入以下Header文件

#import "SeaseAssist.h"

此pod将适用于使用objective-c或Swift的项目。

  • 对于Objective-c项目的最佳效果,将在.pch文件中将SeaseAssist.h导入,您不需要将其导入到引用它的每个类中。
  • 对于Swift项目,您应该不在pod文件中包含use_frameworks!并添加一个包含库的桥接头。如果您必须使用use_frameworks!,则需要将SeaseAssist包含在任何使用其功能的类中。-- 为您的项目添加一个名为ProjectName-Bridging-Header.h的新头文件 -- 将'#import <SeaseAssist/SeaseAssist.h>'添加到您的头文件中 -- 在您的Target Build settings -> Swift Compiler Code Generation -> Objective-C Bridging Header中,添加对新创建的文件的引用。应该是[ProjectName/ProjectName-Bridging-Header.h]

作者

Logan Sease,[email protected]

许可证

SeaseAssist在MIT许可证下提供。有关更多信息,请参阅LICENSE文件。

很抱歉,这里内容众多。我会尽最大努力尝试使这份文档易于阅读。

UI 类:

ClearButton

一款现代化的按钮,拥有优雅的圆角边框、空背景和文字。

ShineButton

按钮具有与按钮的色调颜色相匹配的渐变背景。

RoundedView

一个稍微圆角的视图,带有细边框。

DatePickerTextField

使用日期选择器代替键盘创建一个UITextField。

ValuePickerTextField

具有 Pickerview 而不是键盘的 UITextField

MLTBadgeView

可以在任何 UIView 上使用的徽章。参见 UIView+Badge.h

[view.badge setBadgeValue:@"4"];

SERVICES

EventCounterService

一个用于跟踪应用程序生命周期或每日事件的类

+(NSUInteger)addCountForEvent:(NSString*)event count:(NSInteger)add;
+(NSUInteger)addCountForEvent:(NSString*)event;
+(void)resetCountForEvent:(NSString*)event;
+(NSUInteger)checkCountForEvent:(NSString*)event;
+(NSUInteger)checkDailyEventCount:(NSString*)dailyEvent;
+(NSUInteger)addDailyEventCount:(NSString*)dailyEvent;
+(NSUInteger)addCountForDailyEvent:(NSString*)dailyEvent count:(NSInteger)count;

声音服务

播放声音并维护队列的服务

+ (id)sharedService;
+(void)playSoundAtPath:(NSString*)path;
+(void)playSoundAtPath:(NSString*)path withVolume:(float)volume;
+(void)addSoundToQueueAtPath:(NSString*)path;
-(void)pauseQueue;
-(void)resumeQueue;
-(BOOL)isPlaying;

SpeechService

使用 Siri API 实现的简单文本转语音

+ (id)sharedService;
+(BOOL)isSpeaking;
-(void)speakText:(NSString*)text;

电子邮件服务

一个简单的电子邮件接口,可以在任何地方打开电子邮件查看控制器。

-(void)emailTo:(NSArray*)emails withSubject:(NSString*)subject body:(NSString*)body attachments:(NSArray<MailServiceAttachment*>*)attachments fromVC:(UIViewController*)parent  andCompletion:(void(^)(BOOL success))handler;

图片选择器

一个简单的界面来显示图片选择器。

@interface ImagePickerHelper 
-(void)selectImageFrom:(UIViewController*)source ofType:(UIImagePickerControllerSourceType)type andCompletion:(void(^)(UIImage* image))handler;

网络

HTTPRequest

一个辅助类,无需任何第三方框架即可在单行内异步执行 HTTP 请求。

为了更健壮的网络辅助,请参阅 QwikHttp,以及 QwikJson 用于 JSON 解析。

+(void)jsonRequestToUrl:(NSString*)urlString withMethod:(NSString*)method withHeaders:(NSDictionary*)headers withParams:(NSDictionary*)params withHandler:(void (^)(NSString* response,NSError * error))handler;

+(void)httpRequestToUrl:(NSString*)urlString  withMethod:(NSString*)method withHeaders:(NSDictionary*)headers withParams:(NSDictionary*)params withHandler:(void (^)(NSString* response,NSError * error))handler;

+(NSString*)addParameters:(NSDictionary*)urlParams toUrl:(NSString*)url;

网络连接状态。

查找我们的互联网连接状态。

@interface UIDevice (Reachability)
+(BOOL)connected;
@end

CLASS EXTENSIONS

JSON 序列化和反序列化

###NSDictionary

-(NSString*)toJsonString;
+(NSDictionary*)fromJsonString:(NSString*)json;

###NSArray

-(NSString*)toJsonString;
+(NSArray*)fromJsonString:(NSString*)json;

NSDate 助手函数

-(NSDate*)beginningOfWeek;
-(NSDate*)endOfWeek;

-(NSDate*)beginningOfMonth;
-(NSDate*)endOfMonth;

-(NSDate*)beginningOfYear;
-(NSDate*)endOfYear;
-(NSDate*)dateWithCurrentYear;

-(NSString*)dateToStringWithFormat:(NSString*)format;

-(NSDate*)dateAtEndOfDay;
-(NSDate*)dateWithoutTime;
-(NSDate*)timeValue;
-(BOOL)isOnBeforeOrToday;
-(BOOL)isToday;
-(BOOL)isBeforeToday;

-(BOOL)isBetween:(NSDate*)startDate and:(NSDate*)endDate;
-(NSDate*)dateByAdvancingMonths:(NSInteger)monthCount;
-(BOOL)isAfterDate:(NSDate*)secondDate;
-(BOOL)isBeforeDate:(NSDate*)secondDate;

日期助手函数

public extension Date {
public func isSameDay(as date: Date?) -> Bool
public func nsdate() -> NSDate
public func isOnOrAfter(_ date: Date!) -> Bool
}

NSMutableArray 助手函数

- (void)shuffle;

//wrap an array around a single object (make it the first object and then go to the end
//and start back at the beginning.
-(NSArray*)rotatedArrayAround:(NSInteger)index;
public extension Array {
public mutating func swap(from ind1: Int, to ind2: Int)
}

NSString 助手函数

-(NSInteger)occurancesOfString:(NSString*)test;
-(BOOL)contains:(NSString *)string;
+(NSString*)empty;
- (NSInteger)indexOf: (char)character;
-(NSArray *)splitOnChar:(char)ch;
-(NSString *)substringFrom:(NSInteger)from to:(NSInteger)to;
-(NSString *)stringByStrippingWhitespace;
-(NSString*)initials; //Herby Hancock = HH
+(NSString*)displayString:(float)number; //1,200 = 1.2K
-(NSString*)generateRandom:(int)length;

NSString 验证

-(BOOL)isValidEmail:(BOOL)laxValidation;
-(BOOL)isValidEmail;
-(BOOL)isDigitOfLength:(NSInteger)length;
-(BOOL)isBlank;
+(BOOL)isValidAlphanumbericChars:(NSString*)textString;

字符串格式助手函数

extension String {
public static func isEmpty(_ string: String?) -> Bool

public static func nonWhiteSpaceCharacterCount(_ string: String?) -> Int

public func upperCasedWords() -> String

public func capitalizingFirstLetter() -> String

public var isSingleEmoji: Bool { get }

public var containsEmoji: Bool { get }

public func camelCaseToTitleCase() -> String!

public func camelCaseToUnderscoreCase() -> String!

public func underscoreCaseToCamelCase() -> String!
}

字符串索引和下标操作

extension String
{
public subscript(r: CountableClosedRange<Int>) -> String? { get }
}

加密助手函数

###NSData

-(NSData *) aesEncryptedDataWithKey:(NSData *) key;
-(NSString*)toBase64;
-(NSString*)base64Encoded
-(NSString*)base64Decoded

###NSString

- (NSData *) sha256;
- (NSString *) stringFromMD5;

//secure a string by adding Key Encryption and then Base 64 Encoding it.
- (NSString*)encryptWithKey:(NSString*)key;

NSThread 辅助工具

轻松在主线程或后台线程中运行代码块

+(void)mainThread:(void (^)())main;
+(void)backgroundThread:(void (^)())background;
+(void)delay:(float)length code:(void (^)())function;

UIDevice: 唯一标识符

由于苹果公司不再提供设备级别标识符信息,这是基于MAC地址哈希值的另一种获取标识符的方法。

- (NSString *) uniqueDeviceIdentifier;
- (NSString *) uniqueGlobalDeviceIdentifier;

UIDevice 系统版本

+(BOOL)versionGreaterThanOrEqual:(NSString*)version;

Keychain 辅助工具

读取和写入钥匙串。

@interface UIDevice (Keychain)
+(void)write:(NSString*)value toKeychainWithKey:(NSString*)key appSpecific:(BOOL)appSpecific;
+(NSString*)readFromKeychainWithKey:(NSString*)key appSpecific:(BOOL)appSpecific;
@end

消息提示

###SAMBProgressHUD+Singleton - SAMBProgressHUD 的扩展,以显示不需要将其添加到视图或设置即可的单例加载对话框。

+(void)showWithTitle:(NSString*)title;
+(void)hide;

###UIAlertController - 显示带操作的通知控制器,并通过单行代码获得选择的操作

+(void)showAlertWithTitle:(NSString*)title andMessage:(NSString*)message from:(UIViewController*)controller;
+(void)showDialogWithTitle:(NSString*)title andMessage:(NSString*)message from:(UIViewController*)controller andActions:(NSArray<NSString*>*)buttonTitles completionHandler:(void (^)(NSInteger selected))handler;
+(void)showTextEntryDialogWithTitle:(NSString*)title andMessage:(NSString*)message andPlaceHolder:(NSString*)holder from:(UIViewController*)controller completionHandler:(void (^)(NSString* text))handler;

###UIAlertView

+(void)showWithTitle:(NSString*)title andMessage:(NSString*)message;

###UILabel+Message - 在屏幕上显示一段时间的快速“Toast”消息

+(void)showMessage:(NSString*)message ofSize:(float)fontSize ofColor:(UIColor*)color inView:(UIView*)view forDuration:(float)seconds;

图片

###UIImage 辅助工具

//Add a gassian Blur of the desired amount of pixels
-(UIImage*)blurredImage:(float)amount;


//Get an image from a file, but filled with a different fill color.
- (UIImage *)imageWithColor:(UIColor *)color;

//Scale an image.
- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize;

//turn an image to greyscale
-(UIImage*) toGrayscale;

//capture an uiimage from a uiview
+(UIImage*)fromView:(UIView*)view;

缓存图片并从缓存中加载

+(void)cacheImage:(UIImage*)image forUrl:(NSString*)url;
+(NSString*)cacheFileNameFor:(NSString*)url;
+(UIImage*)cachedImageForUrl:(NSString*)url;
+(void)loadImageToCacheFrom:(NSString*)url;

###UIImageView 辅助 - 从URL设置图片并本地缓存该图片。

-(void)setImageUrl:(NSString*)urlString;

圆形图片

-(void)round;
-(UIImage*)clippedToCircle;

将URL中的图像设置为UIImage View,并启用缓存和默认设置

@interface UIImageView (Networking)
-(void)setImageFromUrl:(NSString*)url withDefault:(UIImage*)defaultImage andRounding:(BOOL)round;

类似于上面的设置URL图像,如果找不到图像,则预先填充首字母

@interface UIImageView (Initials)
-(UILabel*)addInitialsPlaceholder:(NSString*)title circle:(BOOL)circle;
-(void)setImageFromUrl:(NSString*)urlString withPlaceholderString:(NSString*)holder withPlaceHolderImage:(UIImage*)image rounding:(BOOL)round;
-(void)setImageFromUrl:(NSString*)urlString withPlaceholderString:(NSString*)holder withPlaceHolderImage:(UIImage*)image rounding:(BOOL)round completionHandler:(BoolCompletionHandler)handler;

二维码生成

extension String
{
public func toQRCode() -> UIImage?
public func toHiDefQRCode() -> UIImage?
}

动画

###UIView+Bounce 使UI看起来更有生命力,通过添加有趣的弹跳来突出显示重要视图

-(void)bounceFrom:(float)from to:(float)to;
-(void)bounceTo:(float)scale;
-(void)bounce:(BOOL)repeat;
-(void)endBounce;

###UIView+MotionEffects 添加酷炫的运动效果,跟随设备移动,赋予应用深度感

-(void)addMotionEffectsWithOffset:(float)offset;
-(void)addVerticalMotionEffectsWithOffset:(float)offset;
-(void)resizeFullScreenViewAndAddMotionEffectsWithOffset:(float)offset;
-(void)resizeHorizontallyAndAddMotionEffectsWithOffset:(float)offset;
+(void)addMotionEffectsTo:(NSArray*)views withOffset:(float)offset;

###UIView+AnimateShow 动画显示和隐藏一个视图或一组视图

-(void)animateShow;
-(void)animateHide;
+(void)animateShow:(NSArray<UIView*>*)views;
+(void)animateHide:(NSArray<UIView*>*)views;
+(void)animateShow:(NSArray<UIView*>*)views withDelay:(float)delay;

视图外观

###UIView

//round the corners 
-(void)round:(float)cornerRadius withBorderWidth:(float)width andColor:(UIColor*)color;
-(void)round;

//completely circle the view and optionally add a border.
-(void)circleWithColor:(UIColor*)color width:(float)width;
-(void)circle;

//add a visual effect view with a blur
-(UIVisualEffectView*)blur;

//adjust a frame
-(void)adjustFrameXOffset:(float)horizontal yOffset:(float)vertical hOffset:(float)height wOffset:(float)width;

###UIButton+Helpers

- (void)makeGlossy;
- (void)makeClean;
-(void)setTitle:(NSString*)title;

UIColor

+(UIColor*)colorWithHex:(NSString*)hex;
convenience init(r: Int, g: Int, b: Int, alpha: CGFloat = 1.0)

###分段控制器

@interface UISegmentedControl (Helpers)
-(BOOL)setSelectedSegmentNamed:(NSString*)name;
-(NSArray*)allTitles;
-(NSString*)selectedSegementTitle;
@end

###装饰文本框和标签

extension UITextField {

func decorateWithImage(named imageName: String) -> UIImageView

func setBottomBorder(color: UIColor = default) 
}

extension UILabel {
    func addToLeft(image: UIImage?) -> <<error type>>
}

应用视图层次结构

从任何地方找到最顶层的视图控制器。递归搜索应用程序窗口中的导航、标签栏和模态视图控制器### UIViewController+Top

+(UIViewController*)topViewController;
@interface UIView (Search)
-(NSArray*)searchForSubviewsOfType:(Class)searchClass;
@end

背景

模糊显示:用于与覆盖当前上下文模态过渡一起使用

@interface UIViewController (Blur)
-(UIVisualEffectView*)blurBackground;
-(UIVisualEffectView*)blurBackgroundOfTableView:(UITableView*)tableView;
-(UIVisualEffectView*)darkBlurBackground;
-(UIVisualEffectView*)darkBlurBackgroundOfTableView:(UITableView*)tableView;
@end

@interface UITableViewController (Blur)
-(UIVisualEffectView*)blurBackground;
-(UIVisualEffectView*)darkBlurBackground;
@end

###无故事板呈现和模糊

@interface UIViewController (Presentation)
+(void)present:(nonnull UIViewController* )newVC on:(nullable UIViewController*)source;
+(void)present:(nonnull UIViewController* )newVC on:(nullable UIViewController*)source withBlur:(float)blurAmount;

###添加非模糊的背景图片

@interface UIViewController (Background)
-(void)setBackgroundImage:(UIImage*)image withAlpha:(float)alpha;
@end


@interface UITableViewController (Background)
-(void)setBackgroundImage:(UIImage*)image withAlpha:(float)alpha;
@end

UITableView 助手

重新加载表格视图的分区

// NOTE This may cause issues :(
-(void)reloadSection:(NSInteger)section;
-(void)reloadSections:(NSInteger)fromSection to:(NSInteger)toSection;
-(void)deselect

向表格视图添加标题

-(void)setupTableHeader:(UIImage*)image;

导航助手

###添加过渡效果

@interface UINavigationController (Transition)
//add a fade transitions between view controllers for your next push
-(void)addFadeTransition;

//通过弹回或取消显示来返回 - 但让这个来确定哪一个。

UIViewController+Back
-(void)goBackWithAnimation:(BOOL)animates;

清除标签栏

uiNavigationBar.makeClear()
uiNavigationBar.unmakeClear()

键盘助手

UIView
-(void)hideKeyboardOnClick;
-(UIView*)findFirstResponder;
UITextField
-(UIToolbar*)addToolbarWithLeftButton:(NSString*)lTitle withSelector:(SEL)lSelector andRightButton:(NSString*)rTitle withSelector:(SEL)rSelector andTarget:(id)target;

在 NSFileManager 上的路径助手

+(NSString *)myDocumentsPathForFile:(NSString*)fileName;
+(NSString *)tempPathForFile:(NSString*)fileName;

手势

extension UISwipeGestureRecognizer
{
     convenience public init(target: Any?, action: Selector?, direction: Direction) {
}