一个基本的 Toast 消息库用于 iOS。您可以使用和自定义它。欢迎 Pull requests。
您可以下载库文件夹并将其复制到您的项目中。您也可以通过将 pod 'PPSToast', '~> 1.0'
行添加到 Podfile 中使用 CocoaPods 来安装库。(CocoaPods 页面)
在将库添加到您的项目后,只需导入基本头文件:#import "PPSToast.h"
目前,您只能使用两种类型的 Toast:PPSBasicToast
和 PPSSlidingToast
PPSBasicToast *toast = [[PPSBasicToast alloc] initWithViewController:self];
[toast setTitle:@"TEST"];
[toast setDuration:2.0f];
[toast showAfterDuration:5.0f];
PPSSlidingToast *toast = [[PPSSlidingToast alloc] initWithViewController:self title:@"TEST"];
[toast setDuration:2.0f];
[toast setDirection:fromRightToLeft];
[toast show];
您可以为 Toast 消息设置一些选项
-(void) setTitle:(NSString*)title
-(void) setMessage:(NSString*)message
-(void) setDuration:(long)duration
-(void) setDirection:(int)direction // Only for PPSSlidingToast
然后您可以使用以下方式显示您的 Toast 消息
[toast show];
或
[toast showAfterDuration:5.0f];
Copyright (C) 2016 Orhun Mert Simsek
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.