2010-06-21 7 views
15

J'ai un UIScrollView sur lequel j'applique un fond noir, qui se fond dans la barre de défilement. J'ai cherché un moyen de changer la couleur des barres de défilement en blanc, mais je ne peux pas le comprendre. Y a-t-il une bonne façon de faire cela?Couleur de défilement UIScrollView?

Répondre

27

Vous pouvez utiliser "indicatorStyle" propriété:

[scrollView1 setBackgroundColor:[UIColor blackColor]]; 
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite; 
+3

Je peux _never_ rappelez-vous ce nom de la propriété. Tout le reste s'appelle scrollIndicatorSomething excepté celui-ci. Même la saisie semi-automatique ne peut pas me sauver d'une telle propriété mal nommée. – Echelon

+1

Vous pouvez définir la couleur de l'indicateur scrollView, pour tous les UIScrollViews du projet, avec ceci: [[UIScrollView appearance] setIndicatorStyle: UIScrollViewIndicatorStyleWhite]; –

+1

UIScrollView.appearance(). IndicatorStyle = UIScrollViewIndicatorStyle.White – johndpope

2

Les deux indicateurs sont UIScrollView sous vue de UIScrollView. Ainsi, nous pouvons accéder à la sous-vue de UIScrollView et modifier la propriété de subview.

1 .Add UIScrollViewDelegate

@interface ViewController : UIViewController<UIScrollViewDelegate> 
@end 

2. Ajouter scrollViewDidScroll dans la section de mise en œuvre

-(void)scrollViewDidScroll:(UIScrollView *)scrollView1 
{ 
    //get refrence of vertical indicator 
    UIImageView *verticalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-1)]); 
    //set color to vertical indicator 
    [verticalIndicator setBackgroundColor:[UIColor redColor]]; 


    //get refrence of horizontal indicator 
    UIImageView *horizontalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-2)]); 
    //set color to horizontal indicator 
    [horizontalIndicator setBackgroundColor:[UIColor blueColor]]; 
} 

Note: - Parce que ces indicateurs mise à jour chaque fois que vous faites défiler (signifie réinitialiser à la valeur par défaut). SO, nous mettons ce code dans scrollViewDidScroll méthode de délégué.

enter image description here

0
//ScrollView Deleagate 
    func scrollViewDidScroll(scrollView: UIScrollView){ 
     let verticalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as! UIImageView) 
     verticalIndicator.backgroundColor = UIColor.redColor() 


     let horizontalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 2)] as! UIImageView) 
     horizontalIndicator.backgroundColor = UIColor.blueColor() 
    } 
Questions connexes