MNM MNM - 4 months ago 6x
iOS Question

Add black spaces between images in a image view

I have a scrollview that will house some images that I download from the web. I am adding these images into the scrollview but am having trouble adding a black space between them. They are in a vertical scroll not horizontal. I have been thinking of trying to add a space but can't figure out how to do it. Any help would be appreciated.
Here is what I have so far;

private func loadImages() {
myImages = 0;
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.myImages = self.myImages + 1;

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


Add some space between images. If your images are 200 points tall, make the y position of teach image be Int(self.myImages * 210).

or better yet, express it in terms of an image height constant:

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)

I don't know if the background of a scrollview is going to be white or black by default. You might have to set the backgroundColor of the scroll view's contentView to black.