Uiscrollview Browse a group of pictures, and there are gaps between pictures and pictures

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.