在UIScrollview swift中显示我正在使用的图像

时间:2016-10-19 06:53:14

标签: ios arrays swift uiscrollview

说我下载了4张图片 我想要反转我所在图像的数量。现在图像从4/4开始,但我希望它读取1/4。所以基本上我想扭转数字。此功能是查找我所在的图像编号。因此,它越接近最后一个图像,它将数字变为1.我想要相反的效果。我希望最后一个图像的编号变为4.因此,如果我向右滑动,则数字从4/4下降到3/4到2/4到1/4。但我希望第一张图像为1而不是4,所以它是1/4到2/4到3/4到4/4。

以下是我的表现:

//MARK: Set up and download Promotions
var numberPromotions = 0;
var imageSize = 0;
private var promos = Array<(picture: String, path: String)>()

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    print("Scroll finished")
    print("My promot gus" , self.numberPromotions)
    print("Scroll number", scrollView.contentOffset.x)
    print("IMAGE size " , self.imageSize)

    var myPlace : Double = 0
    var totalSize : Double = 0

    let scrollviewOffset = Double(scrollView.contentOffset.x)
    print("int Scroview " , scrollviewOffset)



    totalSize = Double(self.imageSize * (numberPromotions - 1))
    print("To;tal size" , totalSize)
    if scrollviewOffset == 0 {
        myPlace = Double(numberPromotions)
    }else
    {
         myPlace = Double(totalSize / scrollviewOffset)
        print("Gus Place" , myPlace)
    }

    print(myPlace % 1 == 0.5)
    if myPlace % 1 == 0.5
    {
        print("Not a whole number Adding 0.5")
        myPlace = myPlace + 0.5
    }
    print("My place", myPlace)

    var myString : String
    let myPlaceString = String(Int(myPlace))

    myString = myPlaceString + "/" + String(numberPromotions)
    numOfPromoLabel.text = myString

}

1 个答案:

答案 0 :(得分:1)

试试这个:

myString = (String(numberPromotions)-myPlaceString + 1) + "/" + String(numberPromotions)