我想爲我的應用程序創建一個單元測試,檢查導航欄的顏色並將其與應用程序中爲主題顏色保存的用戶默認值進行比較。是否有可能獲得導航欄當前「barTintColor」?
我似乎無法找到訪問酒吧當前顏色的方法。這甚至有可能嗎?
- (void) testColorThemeNavigationBar {
UINavigationBar *navigationBar = [[UINavigationBar alloc] init];
MSMColorManager *manager = [[MSMColorManager alloc]init];
navigationBar = [manager getNavBar];
UIColor *navBarColor = [[UIColor alloc]init];
UIColor *currentThemeColor = [[UIColor alloc] init];
navBarColor = navigationBar.barTintColor;
currentThemeColor = [manager themeColor];
XCTAssertEqualObjects(navBarColor, currentThemeColor);
}
現在我的測試失敗說,對於navBarColor值爲空,而我的currentThemeColor填充了正確的UIColorObject。我相信這是因爲barTintColor方法僅用於設置顏色,而不是檢索。
我也試過backgroundColor無濟於事。
謝謝。
你使用過你的調試器嗎? 'navigationBar'的價值是什麼?這可能是'無'。爲什麼你創建一個導航欄只是爲了扔掉它,並從MSColorManager中獲取一個導航欄? – rmaddy