iOS开源:FFToast - iOS消息通知的简单扩展

fantastic 4年前
   <h2>FFToast</h2>    <p>This is a simple extension of an iOS message notifications that can be used to pop up a prompt at the top or bottom of the screen. You can customize it according to their own display.</p>    <p><img src="https://simg.open-open.com/show/ecf8522351effb5fac0bee0d24c5c896.gif"> <img src="https://simg.open-open.com/show/184e8811bd972fda81a4af03bfb9b851.jpg"></p>    <h2>English instructions</h2>    <h2>Requirements</h2>    <ul>     <li>Requires iOS 8 or later</li>     <li>Requires Automatic Reference Counting (ARC)</li>    </ul>    <h2>Features</h2>    <ul>     <li>Easy to use</li>     <li>Can be easily customized</li>    </ul>    <h2>Installation</h2>    <h3>CocoaPods</h3>    <p>To install FFToast using CocoaPods, please integrate it in your existing Podfile, or create a new Podfile:</p>    <pre>  <code class="language-objectivec">target 'MyApp' do    pod 'FFToast'  end</code></pre>    <p>Then run pod install .</p>    <h3>Manual</h3>    <p>Add FFToast folder to your project</p>    <h2>Usage</h2>    <pre>  <code class="language-objectivec">#import <FFToast/FFToast.h></code></pre>    <p>You can create a message notification that shows the default effect at the top by calling the following method:</p>    <pre>  <code class="language-objectivec">/**   Create and display one Toast     @param title Message title   @param message Message content   @param iconImage Message icon, when toastType is not FFToastTypeDefault iconImage is empty will still have the corresponding icon   @param duration Show duration   */  + (void)showToastWithTitle:(NSString *)title message:(NSString *)message iconImage:(UIImage*)iconImage duration:(NSTimeInterval)duration toastType:(FFToastType)toastType;</code></pre>    <p>Where toastType:</p>    <pre>  <code class="language-objectivec">typedef NS_ENUM(NSInteger, FFToastType) {      //Gray background, no icon      FFToastTypeDefault = 0,      //Green background + success icon      FFToastTypeSuccess = 1,      //Red background + error icon      FFToastTypeError = 2,      //Orange background + warning icon      FFToastTypeWarning = 3,      //Gray blue background + info icon      FFToastTypeInfo = 4,  };</code></pre>    <p>for example:</p>    <pre>  <code class="language-objectivec">[FFToast showToastWithTitle:@"This is the title" message:@"Message content......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];</code></pre>    <p>Title (title), message (message), icon (iconImage) can be empty, FFToast will be based on specific content to adapt.</p>    <p>If you want to show a message notification below the status bar or below the screen, you can set some properties. Set the display position:</p>    <pre>  <code class="language-objectivec">typedef NS_ENUM(NSInteger, FFToastPosition) {        //Displayed at the top of the screen      FFToastPositionDefault = 0,      //Displayed below the status bar      FFToastPositionBelowStatusBar = 1,      //Displayed below the status bar + rounded corners + left and right margins      FFToastPositionBelowStatusBarWithFillet = 2,      //Displayed in the bottom of the screen      FFToastPositionBottom = 3,      //Displayed in the bottom of the screen + rounded      FFToastPositionBottomWithFillet = 4    };</code></pre>    <p>Some other attributes:</p>    <pre>  <code class="language-objectivec">//background color  @property (strong, nonatomic) UIColor* toastBackgroundColor;  //Toast title text color  @property (strong, nonatomic) UIColor* titleTextColor;  //Toast content text color  @property (strong, nonatomic) UIColor* messageTextColor;    //Toast title text font  @property (strong, nonatomic) UIFont* titleFont;  //Toast text font  @property (strong, nonatomic) UIFont* messageFont;    //Toast View corner radius  @property(assign,nonatomic)CGFloat toastCornerRadius;  //Toast View transparency  @property(assign,nonatomic)CGFloat toastAlpha;    //Toast shows the length of time  @property(assign,nonatomic)NSTimeInterval duration;  //Toast disappear animation is enabled  @property(assign,nonatomic)BOOL dismissToastAnimated;    //Toast display position  @property (assign, nonatomic) FFToastPosition toastPosition;</code></pre>    <p>After setting the properties, you can call the following method to display it:</p>    <pre>  <code class="language-objectivec">/**   Show a Toast   */  - (void)show;</code></pre>    <p>or:</p>    <pre>  <code class="language-objectivec">/**   Show a Toast     @param handler Toast click callback   */  - (void)show:(handler)handler;</code></pre>    <p>for example:</p>    <pre>  <code class="language-objectivec">FFToast *toast = [[FFToast alloc]initToastWithTitle:@"This is the title" message:@"Message content......." iconImage:[UIImage imageNamed:@"fftoast_info"]];  toast.toastPosition = FFToastPositionBelowStatusBarWithFillet;  toast.toastBackgroundColor = [UIColor colorWithRed:75.f/255.f green:107.f/255.f blue:122.f/255.f alpha:1.f];  [toast show:^{      //Called when you click message notifications  }];//[toast show];</code></pre>    <p>Hide message notifications: The default 3 seconds after the automatic disappear, slide up the pop-up message to inform it will disappear</p>    <h2>About</h2>    <p>Author: <a href="/misc/goto?guid=4959738184886503634" rel="nofollow,noindex">imlifengfeng</a></p>    <p>WeiBo:@imlifengfeng</p>    <h2>License</h2>    <p>Usage is provided under the <a href="/misc/goto?guid=4958849120936875745" rel="nofollow,noindex">MIT</a> License. See <a href="/misc/goto?guid=4959738185020866235" rel="nofollow,noindex">LICENSE</a> for full details.</p>    <h2>中文使用说明</h2>    <h2>要求</h2>    <ul>     <li>支持iOS 8或更高版本</li>     <li>支持ARC</li>    </ul>    <h2>特点</h2>    <ul>     <li>简单易用</li>     <li>可以很容易自定义</li>    </ul>    <h2>安装</h2>    <h3>CocoaPods</h3>    <p>要使用CocoaPods安装FFToast,请将其集成到您现有的Podfile中,或创建一个新的Podfile:</p>    <pre>  <code class="language-objectivec">target 'MyApp' do    pod 'FFToast'  end</code></pre>    <p>然后 pod install .</p>    <h3>手动</h3>    <p>将FFToast文件夹添加到项目中</p>    <h2>使用方法</h2>    <pre>  <code class="language-objectivec">#import <FFToast/FFToast.h></code></pre>    <p>你可以通过调用下面的方法创建一个显示在顶部的默认效果的消息通知:</p>    <pre>  <code class="language-objectivec">/**   创建并显示一个Toast     @param title 标题   @param message 消息内容   @param iconImage 消息icon,toastType不为FFToastTypeDefault时iconImage为空仍然会有相应icon   @param duration 显示时长   */  + (void)showToastWithTitle:(NSString *)title message:(NSString *)message iconImage:(UIImage*)iconImage duration:(NSTimeInterval)duration toastType:(FFToastType)toastType;</code></pre>    <p>其中的toastType:</p>    <pre>  <code class="language-objectivec">typedef NS_ENUM(NSInteger, FFToastType) {        //灰色背景、无图标      FFToastTypeDefault = 0,      //绿色背景+成功图标      FFToastTypeSuccess = 1,      //红色背景+错误图标      FFToastTypeError = 2,      //橙色背景+警告图标      FFToastTypeWarning = 3,      //灰蓝色背景+信息图标      FFToastTypeInfo = 4,    };</code></pre>    <p>例如:</p>    <pre>  <code class="language-objectivec">[FFToast showToastWithTitle:@"标题" message:@"消息内容......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];</code></pre>    <p>标题(title)、消息内容(message)、图标(iconImage)均可以为空,FFToast会根据具体的内容进行自适应。</p>    <p>如果想在状态栏下方或者屏幕中下方显示消息通知,可以通过设置一些属性实现。 设置显示位置:</p>    <pre>  <code class="language-objectivec">typedef NS_ENUM(NSInteger, FFToastPosition) {        //显示在屏幕顶部      FFToastPositionDefault = 0,      //显示在状态栏下方      FFToastPositionBelowStatusBar = 1,      //显示在状态栏下方+圆角+左右边距      FFToastPositionBelowStatusBarWithFillet = 2,      //显示在屏幕中下方      FFToastPositionBottom = 3,      //显示在屏幕中下方+圆角      FFToastPositionBottomWithFillet = 4    };</code></pre>    <p>其他的一些属性:</p>    <pre>  <code class="language-objectivec">//背景颜色  @property (strong, nonatomic) UIColor* toastBackgroundColor;  //Toast标题文字颜色  @property (strong, nonatomic) UIColor* titleTextColor;  //Toast内容文字颜色  @property (strong, nonatomic) UIColor* messageTextColor;    //Toast标题文字字体  @property (strong, nonatomic) UIFont* titleFont;  //Toast文字字体  @property (strong, nonatomic) UIFont* messageFont;    //Toast View圆角  @property(assign,nonatomic)CGFloat toastCornerRadius;  //Toast View透明度  @property(assign,nonatomic)CGFloat toastAlpha;    //Toast显示时长  @property(assign,nonatomic)NSTimeInterval duration;  //Toast消失动画是否启用  @property(assign,nonatomic)BOOL dismissToastAnimated;    //Toast显示位置  @property (assign, nonatomic) FFToastPosition toastPosition;</code></pre>    <p>设置完属性后,就可以调用下面方法将其显示出来:</p>    <pre>  <code class="language-objectivec">/**   显示一个Toast   */  - (void)show;</code></pre>    <p>或者:</p>    <pre>  <code class="language-objectivec">/**   显示一个Toast     @param handler Toast点击回调   */  - (void)show:(handler)handler;</code></pre>    <p>例如:</p>    <pre>  <code class="language-objectivec">FFToast *toast = [[FFToast alloc]initToastWithTitle:@"标题" message:@"消息内容......." iconImage:[UIImage imageNamed:@"fftoast_info"]];  toast.toastPosition = FFToastPositionBelowStatusBarWithFillet;  toast.toastBackgroundColor = [UIColor colorWithRed:75.f/255.f green:107.f/255.f blue:122.f/255.f alpha:1.f];  [toast show:^{      //点击消息通知时调用  }];//[toast show];</code></pre>    <p>隐藏消息通知: 默认3秒后自动消失,向上滑动弹出的消息通知它也会消失。</p>    <h2>关于</h2>    <p>作者: <a href="/misc/goto?guid=4959738184886503634" rel="nofollow,noindex">imlifengfeng</a></p>    <p>微博:@imlifengfeng</p>    <h2>许可</h2>    <p>该项目在 <a href="/misc/goto?guid=4958849120936875745" rel="nofollow,noindex">MIT</a> 许可协议下使用. 有关详细信息,请参阅 <a href="/misc/goto?guid=4959738185020866235" rel="nofollow,noindex">LICENSE</a> .</p>    <p> </p>    <p> </p>    <p> </p>