2016-06-13 125 views
0

我有一个滚动视图,可以容纳我从网上下载的一些图像。我将这些图像添加到滚动视图中,但无法在它们之间添加黑色空间。他们在一个垂直滚动不水平。我一直在考虑尝试添加空间,但无法弄清楚如何去做。任何帮助,将不胜感激。 这是我到目前为止;在图像视图中的图像之间添加黑色空格

private func loadImages() { 
    myImages = 0; 
    ImageManager.sharedInstance.getAllImagesFromServer({ 
     promotions in 
     for (_,promotion) in promotions { 
      Utility.log(self.dynamicType, msg: promotion.picture, function: "viewDidLoad") 
      self.downloadImage(NSURL(string: promotion.picture)!) 
     }}, 
     onFail: { error_code, detail in Utility.log(self.dynamicType, msg: "Get All Iamges Fail, error_code: \(error_code), detail: \(detail)", 
      function: "viewDidLoad")}) 
} 

func getMyImage(url: NSURL){ 
    getDataFromUrl(url) { (data, response, error) in 
     dispatch_async(dispatch_get_main_queue()) {() -> Void in 
      guard let data = data where error == nil else { return } 
      print(response?.suggestedFilename ?? "") 

      let imageView = UIImageView(image: UIImage(data: data)); 
      imageView.frame = CGRect(x: 0, 
       y: Int(self.myImages * 200), width: Int(self.myScrollView.frame.size.width), height: 200) 
      self.myScrollView.addSubview(imageView) 
      self.myImages = self.myImages + 1; 



      self.myScrollView.contentSize = CGSizeMake(self.myScrollView.frame.size.width, 
       CGFloat(self.myImages * 200)); 
     } 
    } 
} 
+1

只需增加每个帧的“y”值。 – rmaddy

回答

1

在图像之间添加一些空白。如果您的图像高200点,请将教学图像的y位置设为Int(self.myImages * 210)

或更好,但表达它的图像高度不变的条件:

let imageHeight = 200 
let imageWidth = 200 
let image = UIImage(data: data) 
let imageView = UIImageView(image: image); 
imageView.frame = CGRect(
    x: 0, 
    y: Int(self.myImages * imageHeight + 10), 
    width: Int(self.myScrollView.frame.size.width), 
    height: imageHeight) 

我不知道,如果一个滚动视图的背景将是默认白色或黑色。您可能必须将滚动视图的contentView的backgroundColor设置为黑色。

+0

谢谢你的完美工作。我在android上做了这个,但我知道的很快,只是为了让我陷入困境。我很感激 – MNM