iOS Question ImageView - TopMiddle

Alexander Stolte

Expert
Licensed User
Longtime User
is it possible to set the image TopMiddle instead of TopLeft?
B4X:
iv.MODE_TOPLEFT
Because this looks not good:
Bildschirmfoto 2020-07-29 um 11.01.32.png
 

Alexander Stolte

Expert
Licensed User
Longtime User
there is a way to set this, but I am not a NativeObject expert ?
B4X:
Dim naobj As NativeObject = iv                   
iv.ContentMode = naobj.GetField("UIViewContentMode ").GetField("top")
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
To get contentMode use
B4X:
Dim no As NativeObject = ImageView1
intCurrentMode = no.GetField ("contentMode").AsNumber
To set:
B4X:
Dim no As NativeObject = ImageView1
no.SetField ("contentMode", intNewMode)

intNewMode possible values: see https://developer.apple.com/documentation/uikit/uiviewcontentmode?language=objc
UIViewContentModeScaleToFill is equal 0. UIViewContentModeScaleAspectFit is equal 1. UIViewContentModeScaleAspectFill is equal 2. And so on, according an order in Apple's description.

BTW, B4i does not control a value in ImageView.ContentMode. So, you can simply assign ImageView.ContentMode = 5 (UIViewContentModeTop) and to ignore a warning #22.
 
Last edited:
Upvote 0
Top