显示UIPageControl(Swift)的替代方法

时间:2014-12-19 23:10:21

标签: ios swift uipagecontrol

我正在尝试添加一个箭头或类似图像,以便与我在UIFTcrollView中的swift视图相关联。符合enter image description here enter image description here

的内容

(更新) - 我的问题是你如何在你的滚动视图中插入一个图像,告诉它向前或向后取决于你有多少图像。

现在我知道有UIPageControl,但我正在研究另一种方式来显示有一张图片,右边或右边和左边。这是我到目前为止的代码。我会尽我所能来解释我在做什么。

  1. 我的picSource.count是来自携带图片的网站的数据
  2. 我将我的观看次数乘以screenwidth
  3. 这是一个if else语句,如果不发布没有photoprovided图像,则显示bgImage后是否有图片。
  4. 如果您需要更多信息或我是否应该修改,请告诉我。谢谢!

    // Gallery
            if (picSource.count > 1){
    
                var picNum:CGFloat = CGFloat(picSource.count)
    
                // UI News Image Scroller
                var scroll = UIScrollView(frame:CGRectMake(-5, 650, screenWidth, 260))
                scroll.pagingEnabled = true
                scroll.showsHorizontalScrollIndicator = false
                scroll.showsVerticalScrollIndicator = false
                scroll.contentSize = CGSizeMake(picNum*screenWidth, 220)
    
                // Number of views
                var numberOfViews = picSource.count
                var imageName = ""
    
                // Loop to add views to scroll view
                for (var i = 0; i < numberOfViews; i++){
    
                    var myIntValue:Int = Int(screenWidth)
    
                    var xOrigin = i * myIntValue
    
                    // Creates UIImageView instance using myImage
                    var scrollImageView = UIImageView(frame: CGRect(origin: CGPoint(x: xOrigin, y: 5), size: CGSize(width: screenWidth, height: 250)))
    
                    // Tests which image name needs to be used
                    imageName = picSource[i]
    
    
                    // Creates image object using specified image name "...jpg"
                    var url = NSURL(string: "http://www/images/cl/" + adID[adCurrentTag] + "/gallery/" + imageName)
                    var maybeError: NSError?
    
                    if var imageData :NSData = NSData(contentsOfURL: url!,options: NSDataReadingOptions.DataReadingMappedIfSafe, error: &maybeError) {
    
                        var bgImage = UIImage(data:imageData)
                        scrollImageView.contentMode = .ScaleAspectFit
                        scrollImageView.image = bgImage
                        // Adds Image to scroll view
                        scroll.addSubview(scrollImageView)
    
                    }else if let error = maybeError {
    
                        var photoNotProvided = UIImage(named:"noPhoto800x800.png")
                        var photoNotProvidedView = UIImageView(frame: CGRectMake(5, 650.0, screenWidth, 300.0))
                        scrollImageView.image = photoNotProvided
                        scroll.addSubview(scrollImageView)
    
    
                    }
                }
    
    
                border.addSubview(scroll)
    

0 个答案:

没有答案