我试图在用户登录时发送一条 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/