2015-10-13 100 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];