objective-c - 如何在 objective-c 中给出 toast 信息

标签 objective-c iphone xcode uialertview toast

我试图在用户登录时发送一条 toast 消息,并且用户将能够看到一条 toast 消息,说有新数据可用,下面的按钮说下载和取消。但是当下载时它的字体出现在 BOLD 中。请让我知道如何让默认字体看起来正常

代码如下:

 UIAlertView* alert = [[UIAlertView alloc]initWithTitle:msg message:@""delegate:self cancelButtonTitle:@"Download" otherButtonTitles: @"Ignore",nil];

我需要在 toast 消息中以正常字体下载。

最佳答案

我有一个赠送 Toast 的简单代码。

- (void) ShowAlert:(NSString *)Message {
    UIAlertController * alert=[UIAlertController alertControllerWithTitle:nil
                                                                  message:@""
                                                           preferredStyle:UIAlertControllerStyleAlert];
    UIView *firstSubview = alert.view.subviews.firstObject;
    UIView *alertContentView = firstSubview.subviews.firstObject;
    for (UIView *subSubView in alertContentView.subviews) { 
        subSubView.backgroundColor = [UIColor colorWithRed:141/255.0f green:0/255.0f blue:254/255.0f alpha:1.0f];
    }
    NSMutableAttributedString *AS = [[NSMutableAttributedString alloc] initWithString:Message];
    [AS addAttribute: NSForegroundColorAttributeName value: [UIColor whiteColor] range: NSMakeRange(0,AS.length)];
    [alert setValue:AS forKey:@"attributedTitle"];
    [self presentViewController:alert animated:YES completion:nil];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [alert dismissViewControllerAnimated:YES completion:^{
        }];
    });
}

使用

[self ShowAlert:@"Please Enter Your Good Name."];

关于objective-c - 如何在 objective-c 中给出 toast 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43581351/

相关文章:

objective-c - 使用 NSXMLParser initWithStream : no parser delegate methods received

objective-c - 通过交集和并集组合 NSArrays

ios - UIAlertView 和 UILocalNotifications 一样有 fireDate 吗?

xcode - 选择 Xcode 9 Commit 中的所有更改

iphone - 按名称调用 Objective-C 方法

iphone - 如何将制表位添加到 NSAttributedString 并显示在 UITextView 中

iphone - 您可以在 iPhone 的文档文件夹中添加默认文档吗

iphone - ios变量的引用计数

c++ - 第一次尝试构建通用单链表,报undefined symbols错误

objective-c - 重新创建 Cocoa 应用程序菜单栏