自定義iOS的狀態列

2021-06-04 21:28:10 字數 1136 閱讀 9075

如上圖,通過在狀態列顯示自定義資訊,可以給使用者友好又不影響軟體使用的提示。

為此,我們顯得定義乙個自定義狀態列類,包含乙個顯示資訊的label:

@inte***ce customstatusbar : uiwindow

- (void)showstatusmessage:(nsstring *)message;

- (void)hide;

@end

接著,設定大小和系統狀態列一致,背景為黑色:

self.backgroundcolor = [uicolor blackcolor];

到這裡,為了讓自定義的狀態列可以讓使用者看到,還需要設定它的windowlevel。

在ios中,windowlevel屬性決定了uiwindow的顯示層次。預設的windowlevel為uiwindowlevelnormal,即0.0。

const uiwindowlevel uiwindowlevelnormal;

const uiwindowlevel uiwindowlevelalert;

const uiwindowlevel uiwindowlevelstatusbar;

typedef cgfloat uiwindowlevel;

為了能夠覆蓋系統預設的狀態列,我們把自定義的狀態列的windowlevel調高點:

self.windowlevel = uiwindowlevelstatusbar + 1.0f;
最後,為顯示資訊和隱藏新增一點無傷大雅的動畫:

- (void)showstatusmessage:(nsstring *)message

;

[uiview animatewithduration:0.5f animations:^;

} completion:^(bool finished)];

}- (void)hide

completion:^(bool finished)];;

}

完整原始碼:

jason lee @ hangzhou

blog: 

weibo: @思禽飲霜

自定義狀態列UIStatusBar

類似微博傳送資訊時,在狀態列提示訊息的效果。主要實現思想是繼承uiwindow,然後設定windowlevel的級別高於uistatusbar。最後把自定義的statusbar放置在原來的statusbar指定的位置上。import inte ce sendvoicetipsview uiwindo...

自定義狀態列notification布局

布局定義custom notification.xml 布居中引用的樣式檔案styles.xml package cn.itcast.tabhost import android.content.intent import android.graphics.color import android....

自定義狀態列的顯示效果

使用作用域插槽獲取當前行資料 使用者列表區域 stripe隔行變色,border加 豎線 userlist stripe border 加索引頁 index label el table column 姓名 prop username el table column 郵箱 prop email el...