JIbber4568
JIbber4568

Reputation: 839

Add UIImageView to UIScrollView

Was hoping someone could point out what is wrong with this.

My storyboard has a UIScrollView named timelineScrollView and a UIImageView named imageviewtest.

I am creating an image that is a simple straight line. If I add it to the UIImageView it displays fine. However if I add it to the UIScrollView then nothing displays.

How do I get it to display within the UIScrollView?

func drawingTest(){

    let drawing = DrawingHelper()
    let imageSize2 = CGSize(width: 100, height: 60)
    let fromPoint: CGPoint = CGPoint(x: 0, y:0)
    let toPoint: CGPoint = CGPoint(x: 50, y:0)


    imageviewtest.image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)

    var imageView = UIImageView()
    var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
    imageView.image = image;


    var scrollViewAreaSize = CGSize(width: 100, height: 60)
    timelineScrollView.contentSize = scrollViewAreaSize
    timelineScrollView.addSubview(imageView)
}

Upvotes: 2

Views: 370

Answers (1)

Vlad
Vlad

Reputation: 7260

Set an appropriate frame to your image view or initialize UIImageView with your image:

var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
var imageView = UIImageView(image:image)

From documentation:

This method adjusts the frame of the receiver to match the size of the specified image.

Upvotes: 1

Related Questions