我有一个UIScrollView,我正在应用黑色背景,它在滚动条中混合。我一直在寻找一种方法将滚动条颜色更改为白色,但我无法弄清楚。有没有适当的方法来做到这一点?UIScrollView滚动条颜色?
15
A
回答
27
您可以使用 “indicatorStyle” 属性:
[scrollView1 setBackgroundColor:[UIColor blackColor]];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
2
两个UIScrollView的指标是UIScrollView的子视图。那么,我们可以通过 访问UIScrollView的子视图并更改子视图的属性。
1。新增UIScrollViewDelegate
@interface ViewController : UIViewController<UIScrollViewDelegate>
@end
2.添加scrollViewDidScroll在实现部分
-(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]];
}
注: - 由于这些指标更新,每次当您滚动 (意味着重置为默认值)。所以,我们把这段代码放在scrollViewDidScroll 的委托方法中。
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()
}
相关问题
- 1. 自定义UIScrollView滚动条颜色?
- 2. dropdownlist的滚动条颜色变化
- 3. 如何更改eclipse滚动条颜色
- 4. 使用css改变滚动条颜色
- 5. 如何更改滚动条的颜色
- 6. 如何更改滚动条的颜色
- 7. 垂直滚动条颜色不变
- 8. 更改UITextView滚动条颜色
- 9. 页面内滚动条的颜色
- 10. 改变滚动条的颜色?
- 11. 获取滚动条的颜色
- 12. 滚动条在UIScrollView和UIWebview
- 13. UIScrollView中的UIButton颜色在滚动时设置为错误的颜色
- 14. 滚动颜色js
- 15. JQuery滚动动画颜色
- 16. iPhone:TableView里面的UIScrollview,显示滚动条滚动条
- 17. 在Lion中设置打火机(白色)滚动条颜色
- 18. Spark Label滚动颜色
- 19. 自定义UIScrollView的滚动条
- 20. UIScrollView不滚动
- 21. 的UIScrollView滚动
- 22. UIScrollVIew不滚动
- 23. 的UIScrollView滚动
- 24. UIScrollView不滚动...
- 25. 使UIScrollview滚动
- 26. 动画UIScrollView滚动
- 27. 用jQuery滚动动态颜色变化
- 28. UIScrollView滚动问题
- 29. UIScrollView不滚动ios6
- 30. UIScrollView滚动检测
我可以_永远_记得这个属性名。除此之外,其他一切都称为scrollIndicatorSomething。即使自动完成也不能拯救我从这样一个严重命名的属性。 – Echelon 2012-01-18 20:01:13
您可以使用以下设置为项目中的所有UIScrollViews设置scrollView指标的颜色: [[UIScrollView appearance] setIndicatorStyle:UIScrollViewIndicatorStyleWhite]; – 2015-01-20 11:59:40
UIScrollView.appearance()。indicatorStyle = UIScrollViewIndicatorStyle.White – johndpope 2015-10-08 05:59:18