samedi 27 juin 2015

swift - I'm dumb and my subview wont obey and correctly size itself

I feel like this is a softball for you veterans, but I'm having a lot of trouble resizing the subview of my UIImageView... here is what I got:

var myImageView:UIImageView!

var tmpView:UIImageView!

myImageView is my "main" UIImageView, and I'm treating tmpView as a subview... now I've tried both with and without auto layout on, but I've set the constraints of myImageView s.t. myImageView takes up the whole screen. I've confirmed this to be true by setting myImageView.image = UIImage...etc.

Here is my code for initializing the image and adding it to the subview:

self.tmpView.image = UIImage(named: "myImage.png")
self.tmpView.frame = CGRect(x: 0, y: 0, width: 200, height: 300)
self.imageView2.addSubview(self.tmpView)

Now here is where I am running into problems - no matter what I set tmpView's height and width to, the size never changes. Interestingly though, changing x,y does have an effect on the position of the subview.

Here are my questions: 1) Why do both x and y obey nicely, but width and height do not?

2) How do I fix this, and is it best to do so programmatically or through the storyboard?

Aucun commentaire:

Enregistrer un commentaire