個人覺得這種提示效果用在UITableView上要比HUD優雅美觀,而其他情況下的提示,用HUD比較好
源碼簡介易懂,用起來也很方便
pod導入相對很簡單,主要講怎么手動導入這個庫
引用頭文件#import "TSMessageView.h"
TSMessageNotificationType:提示樣式,包含 TSMessageNotificationTypeMessage,TSMessageNotificationTypeWarning,TSMessageNotificationTypeError,TSMessageNotificationTypeSuccess,分別用來做展示信息,提示警告,提示錯誤,提示成功
TSMessageNotificationPosition:提示位置,包含 TSMessageNotificationPositionTop,TSMessageNotificationPositionNavBarOverlay,TSMessageNotificationPositionBottom,分別展示在頂部(有NavigationBar的話緊挨著它),遮擋NavigationBar(實際測試并不好用),底部
TSMessageNotificationDuration:提示消失方式,包含 TSMessageNotificationDurationAutomatic,TSMessageNotificationDurationEndless,含義是自動消失和手動消失
[TSMessage showNotificationWithTitle:@"標題" subtitle:@"詳細信息" type:TSMessageNotificationTypeError];
[TSMessage showNotificationInViewController:self title:@"標題" subtitle:@"詳細信息" image:nil type:TSMessageNotificationTypeMessage duration:TSMessageNotificationDurationAutomatic callback:nil buttonTitle:@"按鈕標題" buttonCallback:^{ NSLog(@"按鈕事件"); } atPosition:TSMessageNotificationPositionTop canBeDismissedByUser:YES];
[[TSMessageView appearance] setTitleFont:[UIFont boldSystemFontOfSize:6]];//標題字體大小[[TSMessageView appearance] setTitleTextColor:[UIColor redColor]];//標題字體顏色[[TSMessageView appearance] setContentFont:[UIFont boldSystemFontOfSize:10]];//內容字體大小[[TSMessageView appearance]setContentTextColor:[UIColor greenColor]];//內容字體顏色[[TSMessageView appearance]setErrorIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];//自定義失敗圖片[[TSMessageView appearance]setSuccessIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];//自定義成功圖片[[TSMessageView appearance]setMessageIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];//自定義信息展示圖片[[TSMessageView appearance]setWarningIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];//自定義警告圖片
首先你的樣式應該是
TSMessageNotificationPositionNavBarOverlay,如:
if (self.navigationController.navigationBarHidden == NO) { self.navigationController.navigationBarHidden = YES;}//必須要加 [TSMessage showNotificationInViewController:self title:@"標題" subtitle:@"詳細信息" image:nil type:TSMessageNotificationTypeMessage duration:TSMessageNotificationDurationAutomatic callback:nil buttonTitle:@"按鈕標題" buttonCallback:^{ NSLog(@"按鈕事件"); } atPosition:TSMessageNotificationPositionNavBarOverlay canBeDismissedByUser:YES];
然后在
- (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:(void (^)())animationFinished
方法下加入
if (currentView.messagePosition == TSMessageNotificationPositionNavBarOverlay) { UIViewController *vc = currentView.viewController; vc.navigationController.navigationBarHidden = NO;}
注: 文章由我們 iOS122 的小伙伴 * 整理,喜歡就一起參與: iOS122 任務池
|
新聞熱點
疑難解答