CRToast
是一个库,可以轻松创建顶部或通过推挤状态栏或导航栏出现的通知。CRToast
最初基于CWStatusBarNotification。
CRToast
使用ARC并且需要iOS 7.0以上。适用于iPhone和iPad。
将项目或源文件添加到您的项目中。
可以通过CRToastManager
的showNotificationWithOptions:completionBlock:
方法创建通知,这将把指定的选项排队。您可以使用在CRToast.h
中的键在字典中提供您通知的选项
此代码
NSDictionary *options = @{
kCRToastTextKey : @"Hello World!",
kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
kCRToastBackgroundColorKey : [UIColor redColor],
kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
};
[CRToastManager showNotificationWithOptions:options
completionBlock:^{
NSLog(@"Completed");
}];
生成以下内容
CRToast
非常可定制。从UIStringDrawing
的drawInRect:withAttributes:
书籍中得出的提示,通知是通过填充所有选项的字典创建的。
CRToast
允许设置以下内容
标题和副标题文本,包括
CRToast
还允许自定义动画。这包括。
CRToast
允许任何通知响应不同类型的触摸交互(点击、滑动)。交互响应者可以设置为默认或逐通知设置。您可以设置的交互类型包括
CRToastInteractionTypeSwipeUp
CRToastInteractionTypeSwipeLeft
CRToastInteractionTypeSwipeDown
CRToastInteractionTypeSwipeRight
CRToastInteractionTypeTapOnce
CRToastInteractionTypeTapTwice
CRToastInteractionTypeTwoFingerTapOnce
CRToastInteractionTypeTwoFingerTapTwice
也有通配符交互类型,覆盖一系列交互
CRToastInteractionTypeSwipe
CRToastInteractionTypeTap
CRToastInteractionTypeAll
任何交互都可以使用CRToastInteractionResponder
来响应,它们可以用以下构造函数创建
+ (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType)interactionType
automaticallyDismiss:(BOOL)automaticallyDismiss
block:(void (^)(CRToastInteractionType interactionType))block;
您可以将一组CRToastInteractionResponder
对象设置为首选项中kCRToastInteractionRespondersKey
的键,使得所有通知都响应某种交互,或者对任何一个指定的通知,让交互响应者只为该通知工作。
您还可以在任何时候使用以下方法关闭当前通知:
+ (void)dismissNotification:(BOOL)animated;
要呈现用户必须关闭的通知,可以将kCRToastTimeIntervalKey
的值通过@(DBL_MAX)
传递,并设置一个将关闭通知的交互响应者。
所有属性都设置了合理的默认值,但您可以使用CRToastManagers
的setDefaultOptions:
方法为应用程序的通知设置一组默认选项。
The MIT License (MIT)
Copyright (c) 2013 Collin Ruffenach
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.