CRToast
是一个库,它可以轻松创建显示在状态栏或导航栏上方或旁侧的通知。 CRToast
最初基于 CWStatusBarNotification 开发。
CRToast
使用 ARC 并需要 iOS 7.0+。适用于 iPhone 和 iPad。
将文件夹 CRToast
复制到您的项目中。
可以通过 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
,在默认设置中有所有通知响应某特定的交互,或者在任何给定的通知中使交互响应者仅适用于该通知。
您还可以随时使用以下代码 dismiss 当前通知
+ (void)dismissNotification:(BOOL)animated;
您可以提供必须由用户 dismiss 的通知,通过传递 @(DBL_MAX)
作为 kCRToastTimeIntervalKey
的值,并设置将 dismiss 通知的交互响应者。
所有属性都已设置了合理的默认值,但是您可以使用 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.