uiimageview - Overriding the class's property swift -


i want override contentmode of uiimageview wrote code doesn't seem work expected.

class aspectfituiimageview: uiimageview {      override var contentmode: uiviewcontentmode {         {             return .scaleaspectfit         }          set {             // contentmode = contentmode         }     } } 

can 1 tell me wrong?

you should set contentmode in awakefromnib() so:

class aspectfituiimageview: uiimageview {      override func awakefromnib() {        super.awakefromnib()        contentmode = .scaleaspectfit     }  } 

or if not planning on using nib or storyboard, can use following:

override init(frame: cgrect) {     super.init(frame: frame)     contentmode = .scaleaspectfit } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -