日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

【转】iOS类似Android上toast效果

發布時間:2025/3/13 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】iOS类似Android上toast效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文網址:http://m.blog.csdn.net/article/details?id=50478737

做過Android開發的人都知道toast,它會在界面上顯示一排黑色背景的文字,用于提示用戶信息。但iOS上并沒有類似的控件,so,自己寫一個吧。

原理:

說白了,Android中的toast可以理解成iOS中的一個黑色背景的UILabel。。。

效果圖:

是不是還可以,什么背景顏色,字體大小,位置,統統都是可以自己設置的。

代碼:

?

//尺寸設置 #define aiScreenWidth [UIScreen mainScreen].bounds.size.width #define aiScreenHeight [UIScreen mainScreen].bounds.size.height #define STATUS_BAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height #define NAVIGATION_BAR_HEIGHT self.navigationController.navigationBar.frame.size.height #define TAB_BAR_HEIGHT self.tabBarController.tabBar.frame.size.height



?

?

- (void) addToastWithString:(NSString *)string inView:(UIView *)view {CGRect initRect = CGRectMake(0, STATUS_BAR_HEIGHT + 44, aiScreenWidth, 0);CGRect rect = CGRectMake(0, STATUS_BAR_HEIGHT + 44, aiScreenWidth, 22);UILabel* label = [[UILabel alloc] initWithFrame:initRect];label.text = string;label.textAlignment = NSTextAlignmentCenter;label.textColor = [UIColor whiteColor];label.font = [UIFont systemFontOfSize:14];label.backgroundColor = [UIColor colorWithRed:0 green:0.6 blue:0.9 alpha:0.6];[view addSubview:label];//彈出label[UIView animateWithDuration:0.5 animations:^{label.frame = rect;} completion:^ (BOOL finished){//彈出后持續1s[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(removeToastWithView:) userInfo:label repeats:NO];}]; }- (void) removeToastWithView:(NSTimer *)timer {UILabel* label = [timer userInfo];CGRect initRect = CGRectMake(0, STATUS_BAR_HEIGHT + 44, aiScreenWidth, 0); // label消失[UIView animateWithDuration:0.5 animations:^{label.frame = initRect;} completion:^(BOOL finished){[label removeFromSuperview];}]; }


使用方法:

?

?

[self addToastWithString:@"更新到最新數據啦~" inView:self.view];

轉載于:https://www.cnblogs.com/wi100sh/p/5600772.html

總結

以上是生活随笔為你收集整理的【转】iOS类似Android上toast效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。