iOS Tutorial change Imageview.Bitmap color

hi,

if you would like to change the color of your Imageview.Bitmap than you could just
do it like this:

B4X:
ImageView1.TintColor = Colors.RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))

but it seems like that it is not working always (and on all devices like iphone 4)

so there is another option that worked for me:

B4X:
Sub BmpColor(img As ImageView, color As Int)
    Dim NaObj As NativeObject = Me
    NaObj.RunMethod("BmpColor::",Array(img,NaObj.ColorToUIColor(color)))
End Sub

#If OBJC
- (void)BmpColor: (UIImageView*) theImageView :(UIColor*) Color{
theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[theImageView setTintColor:Color];
}
#end if

Regards, ilan :)

EDIT: i dont know why the second code does worked for me and the first not. it seems like the build in b4i function does the same but it did not worked when i tried it on my iphone 4 and simulator. the second code did worked.
 

Attachments

  • bmpcolor.zip
    65.1 KB · Views: 399
Last edited:

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi @ilan, if you want you can extend the method with background color :)

B4X:
#If OBJC
- (void)BmpColor: (UIImageView*) theImageView :(UIColor*) Color : (UIColor*)Color2 {
theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
theImageView.backgroundColor =  Color2;
[theImageView setTintColor:Color];
}
#end if

Sub BmpColor(img As ImageView, color As Int, color2 As Int)
    Dim NaObj As NativeObject = Me
    NaObj.RunMethod("BmpColor:::",Array(img,NaObj.ColorToUIColor(color),NaObj.ColorToUIColor(color2)))
End Sub
 
Top