I'm trying to add an arrow or like an image to correlate to how many view I have in my UIScrollView in swift. Something in line of this enter image description here enter image description here

Now I know there is the UIPageControl but I'm looking into an alternative way to show that there is a picture and to the right or right and left. This is the code I have so far. I'll try the best I can to explain what I'm doing.

  1. My picSource.count is data from a website that is carrying pictures
  2. I'm multiplying my number of views by the screenwidth
  3. This is an if else statement that shows if a picture is there post bgImage if not post no photoprovided image.

Let me know if you need more information or if I should revise. Thanks!

// 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

                }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



Related posts

Recent Viewed