我在Xcoode中开发了一个应用程序,并添加了一个ScrollView。现在我在一行中添加了一些小图片。如何在Swift中将图像添加到ScrollView中
let myImages = ["BallBeispielBlau.png","BallBeispielRot.png","BallBeispielGelb.png","BallBeispielBlau.png","BallBeispielRot.png","BallBeispielGelb.png","BallBeispielBlau.png","BallBeispielRot.png","BallBeispielGelb.png"]
let imageWidth:CGFloat = 66
let imageHeight:CGFloat = 66
var xPosition:CGFloat = 0
var scrollViewSize:CGFloat=0
for image in myImages {
let myImage:UIImage = UIImage(named: image)!
let myImageView:UIImageView = UIImageView()
myImageView.image = myImage
let LongTapGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "InfosZuEinemEvent:")
LongTapGestureRecognizer.minimumPressDuration = 1.0;
myImageView.addGestureRecognizer(LongTapGestureRecognizer)
myImageView.userInteractionEnabled = true
myImageView.frame.size.width = imageWidth
myImageView.frame.size.height = imageHeight
myImageView.frame.origin.x = xPosition
myImageView.frame.origin.y = 0
ScrollViewFreunde.addSubview(myImageView)
ScrollViewFreunde.showsHorizontalScrollIndicator = false
xPosition += imageWidth
scrollViewSize += imageWidth
}
ScrollViewFreunde.contentSize = CGSize(width: scrollViewSize, height: imageHeight)
这工作正常,但我想它,六幅图像,从而落入五个镜像后的图像,其中第一图像在显示使第二排。我用if语句尝试它,但它不起作用。我希望你能帮助我。
感谢您的帮助。
添加代码,如果你试图语句,以便我们可以告诉你如何解决它。否则,你应该看看使用'UICollectionView'。它的目的是为了做到这一点。 –
看到这一次,它可以帮助你http://stackoverflow.com/questions/24056219/multiple-image-in-scrollview/24056398#24056398 –