ios - Masking a UIImageView doesn't work -


i have uiimageview set up:

let picture = uiimageview(frame: imageframe) picture.image = uiimage(named: image) 

you can see here:

now want mask constant size, because i's going random pictures random sizes, i've created uiview:

let frame = cgrect(x: 0, y: cgrectgetmaxy(menuline.frame) + heightforsize * 0.05, width: view.bounds.width, height: heightforsize * 0.9) let mask = uiview(frame: frame) mask.backgroundcolor = uicolor.whitecolor() 

when add subview view looks this:

but when try mask it:

picture.maskview = mask 

it looks this, going wrong here?

uiimageview respects contentmode serve purpose here easier mask. set imageview fixed size want images fit in. if want image squeeze in , show black bars if tall example, use uiviewcontentmode.scaleaspectfit. more best uiviewcontentmode.scaleaspectfill. maintain aspect ratio of image , scale until fills imageview box you've created. play 2 modes , others see effects.

let imageview = uiimageview(image: uiimage(named: "myimage")) imageview.frame = cgrect(x: 0, y: 0, width: 100, height: 100) imageview.contentmode = .scaleaspectfill 

more info on various contentmodes can try here.

https://developer.apple.com/reference/uikit/uiviewcontentmode


Comments