2015-10-13 101 views
0

這是HomeView enter image description here更改滾動條背景IOS

當有人在「銀行」按鈕被竊聽。 Action將加載BaseviewController。

這是按鈕操作。

HomeViewController.m

BaseViewController *clickbutton = [[BaseViewController alloc] initWithNibName:@"BaseViewController" bundle:nil] ; 
[self presentViewController:clickbutton animated:YES completion:nil]; 

這是基本視角 enter image description here

有將加載每個視圖的滾動條。滾動條 背景是綠色的。然後在這裏更改背景是 問題。

BaseViewController.m

-(void)ViewDidLoad{ 

    PriorityViewController *obj ; 

    UINavigationController *nav; 

    obj = [[ PriorityViewController alloc] initWithNibName:@"PriorityViewController" bundle:nil] ; 

    nav = [[UINavigationController alloc] initWithRootViewController:obj]; 

    nav.view.frame = rect; 

    [self.view addSubview:self.nav.view]; 

} 

當挖 '服務請求'。

OtherBankTransferViewController *obj; 
    obj = [[OtherBankTransferViewController alloc]initWithNibName:@"OtherBankTransferViewController" bundle:nil]; 

[self.navigationController pushViewController:obj animated:YES ]; 

這將加載一樣喜歡我在這裏上傳第二圖像。 我只是想改變滾動條的背景顏色 我想將滾動條變成黑色。

我不知道。如果有人解釋我! 在此先感謝。

+0

[myScrollView setBackgroundColor:的UIColor blackcolor]]; – BHUMICA

+0

點擊服務請求後,它將加載另一個視圖控制器(導航)。 –

+0

您的滾動條在哪個視圖中,您想在哪裏更改顏色? – BHUMICA

回答

0

方法1: 而是在每個視圖控制器初始化滾動條的,爲什麼不ALLOC初始化它在基本視點控制器,並通過它的實例給所有視圖控制器。 由於現在所有的ViewController都會有相同的實例,所以很容易改變scrollBar的背景。

方法2: 每當你想改變滾動條的顏色,您可以張貼通知, 添加觀察員您發佈通知,該通知可以傳遞你想要的所有滾動條來設置顏​​色。

發佈通知,當你想改變顏色

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:@"someKey"]; 
[[NSNotificationCenter defaultCenter] postNotificationName: @"TestNotification" object:nil userInfo:userInfo]; 

添加觀察員在viewDidLoad中

[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(receiveTestNotification:) 
    name:@"TestNotification" 
    object:nil]; 

方法來處理收到的通知

- (void) receiveTestNotification:(NSNotification *) notification{ 

    NSDictionary *userInfo = notification.userInfo; 
    UIColor *backGroundColor = [userInfo objectForKey:@"someKey"]; 
    // assign this color to your scrollBar in each ViewController 

} 

在viewDidUnload REMOVING觀測

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"TestNotification" object:nil];