Swift 如何定制UIScrollview';s指示器位置?
我在tableview的单元格中有一个滚动视图 我正在尝试将scrollview的指示器的位置设置为顶部 我必须检查水平指示器 正如你所看到的。。。我想把位置调到最上面 我的自定义指示器:黑色和蓝色指示器 默认指示器:底部…灰色指示器 我还尝试使用该方法设置 scrollView.ScrollIndicationSets=UIEdgeInsets(顶部:30,左侧:0,底部:0,右侧:10) 我解决了我的问题 有两种方法 1。使用UIPageController 2。使用UIView制作自定义指示器。Swift 如何定制UIScrollview';s指示器位置?,swift,uitableview,uiscrollview,horizontalscrollview,Swift,Uitableview,Uiscrollview,Horizontalscrollview,我在tableview的单元格中有一个滚动视图 我正在尝试将scrollview的指示器的位置设置为顶部 我必须检查水平指示器 正如你所看到的。。。我想把位置调到最上面 我的自定义指示器:黑色和蓝色指示器 默认指示器:底部…灰色指示器 我还尝试使用该方法设置 scrollView.ScrollIndicationSets=UIEdgeInsets(顶部:30,左侧:0,底部:0,右侧:10) 我解决了我的问题 有两种方法 1。使用UIPageController 2。使用UIView制作自定
class AdvertiseCell: UITableViewCell, UIScrollViewDelegate {
var advArray = [PFFile]()
var advSectionArray = [UIImageView]()
//declaire Custom Indicator using UIView
var scrollIndicator = UIView()
var indicator = UIView()
@IBOutlet weak var pagingView: UIScrollView!
@IBOutlet weak var pageController: UIPageControl!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let pagingViewHeight = self.pagingView.frame.height
let pagingViewWidth = self.pagingView.frame.width
//set section size
advSectionArray.append(UIImageView(frame: CGRectMake(5, 5 , pagingViewWidth-10, pagingViewHeight-10)))
advSectionArray.append(UIImageView(frame: CGRectMake(pagingViewWidth * 1 + 5, 5 , pagingViewWidth-10, pagingViewHeight-10)))
advSectionArray.append(UIImageView(frame: CGRectMake(pagingViewWidth * 2 + 5, 5 , pagingViewWidth-10, pagingViewHeight-10)))
//add imageview
self.pagingView.addSubview(advSectionArray[0])
self.pagingView.addSubview(advSectionArray[1])
self.pagingView.addSubview(advSectionArray[2])
self.pagingView.contentSize = CGSizeMake(self.pagingView.frame.width * 3, self.pagingView.frame.height)
self.scrollIndicator = UIView(frame: CGRect(x: 0, y: 0, width: pagingViewWidth, height: 3))
self.indicator = UIView(frame: CGRect(x: 0, y: 0, width: pagingViewWidth / 3, height: 3))
self.scrollIndicator.backgroundColor = UIColor.blackColor()
self.indicator.backgroundColor = UIColor(red: 0.0/255, green: 109/255, blue: 242/255, alpha: 1)
super.addSubview(scrollIndicator)
super.addSubview(indicator)
//It is very important!
self.pagingView.delegate = self
self.pageController.currentPage = 0
self.pageController.numberOfPages = 3
loadAdvertise()
}
func scrollViewDidScroll(sclView: UIScrollView) {
let page:Int = Int(floor(sclView.contentOffset.x / UIScreen.mainScreen().bounds.size.width))
self.pageController.currentPage = page
let pages : CGFloat
pages = CGFloat(self.pageController.numberOfPages)
self.indicator.frame = CGRectMake(sclView.contentOffset.x / pages, 0, self.pagingView.frame.width / 3, 3);
}
看看我的结果
谢谢,我解决了我的问题
有两种方法
1。使用UIPageController
2。使用UIView制作自定义指示器。
class AdvertiseCell: UITableViewCell, UIScrollViewDelegate {
var advArray = [PFFile]()
var advSectionArray = [UIImageView]()
//declaire Custom Indicator using UIView
var scrollIndicator = UIView()
var indicator = UIView()
@IBOutlet weak var pagingView: UIScrollView!
@IBOutlet weak var pageController: UIPageControl!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let pagingViewHeight = self.pagingView.frame.height
let pagingViewWidth = self.pagingView.frame.width
//set section size
advSectionArray.append(UIImageView(frame: CGRectMake(5, 5 , pagingViewWidth-10, pagingViewHeight-10)))
advSectionArray.append(UIImageView(frame: CGRectMake(pagingViewWidth * 1 + 5, 5 , pagingViewWidth-10, pagingViewHeight-10)))
advSectionArray.append(UIImageView(frame: CGRectMake(pagingViewWidth * 2 + 5, 5 , pagingViewWidth-10, pagingViewHeight-10)))
//add imageview
self.pagingView.addSubview(advSectionArray[0])
self.pagingView.addSubview(advSectionArray[1])
self.pagingView.addSubview(advSectionArray[2])
self.pagingView.contentSize = CGSizeMake(self.pagingView.frame.width * 3, self.pagingView.frame.height)
self.scrollIndicator = UIView(frame: CGRect(x: 0, y: 0, width: pagingViewWidth, height: 3))
self.indicator = UIView(frame: CGRect(x: 0, y: 0, width: pagingViewWidth / 3, height: 3))
self.scrollIndicator.backgroundColor = UIColor.blackColor()
self.indicator.backgroundColor = UIColor(red: 0.0/255, green: 109/255, blue: 242/255, alpha: 1)
super.addSubview(scrollIndicator)
super.addSubview(indicator)
//It is very important!
self.pagingView.delegate = self
self.pageController.currentPage = 0
self.pageController.numberOfPages = 3
loadAdvertise()
}
func scrollViewDidScroll(sclView: UIScrollView) {
let page:Int = Int(floor(sclView.contentOffset.x / UIScreen.mainScreen().bounds.size.width))
self.pageController.currentPage = page
let pages : CGFloat
pages = CGFloat(self.pageController.numberOfPages)
self.indicator.frame = CGRectMake(sclView.contentOffset.x / pages, 0, self.pagingView.frame.width / 3, 3);
}
看看我的结果
谢谢