2016-06-13 68 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

相關問題