---restore content starts---
Uiscrollview is a set of view that can be browsed, as long as its properties
The pagingenabled is set to true. The concrete process is this,
1: Add a group of pictures to the Uiscrollview in order from left to right
2:pagingenabled set to True
Only two steps, very convenient
But you will find that these pictures are one after another, and that is the effect:
We found that the photo app in iOS comes with the same view as this, but there is a space between each picture,
When you flick with your finger, you will find that the picture on the left or right is not completely connected.
Overridefunc viewdidload () {super.viewdidload () ScrollView=Uiscrollview (frame:view.bounds) scrollview.pagingenabled=trueScrollview.backgroundcolor=Uicolor.blackcolor () View.addsubview (scrollView) pageimages=[UIImage (named:"Photo1.png")!, UIImage (named:"Photo2.png")!, UIImage (named:"Photo3.png")!, UIImage (named:"Photo4.png")!, UIImage (named:"Photo5.png")!] Let PageCount=Pageimages.count let Dx:cgfloat= 50var itemwidth= scrollView.bounds.width + dx * CGFLOAT (2.0) forIinch 0.. <pagecount{var frame=scrollview.bounds frame.origin.x= Itemwidth *cgfloat (i) FRAME.ORIGIN.Y=0.0Frame.size.width=itemwidth let Newpageview=Uiimageview (image:pageimages[i]) Newpageview.contentmode=Uiviewcontentmode.scaleaspectfit Newpageview.frame= Cgrectinset (frame, DX,0) Scrollview.addsubview (Newpageview)} var tt=view.bounds.size Scrollview.frame= CGRect (x:-dx, Y:0, Width:itemwidth, height:tt.height) let Pagesscrollviewsize=scrollView.frame.size scrollview.contentsize= Cgsizemake (Itemwidth *cgfloat (Pageimages.count), pagesscrollviewsize.height)}
The principle is to widen each picture, and then add the DX spacing, so that the size of the picture back to the original, the middle also has an interval
The concrete effect is this:
33 to
The above effect is the same as the photo browsing that comes with iOS, and the experience is much more comfortable than the above one.
---restore content ends---
Uiscrollview Browse a group of pictures, and there are gaps between pictures and pictures