iOS Question Obj C Class and #IF OBJC / An attempt at ViewBadger functionality for iOS

henrywood

Active Member
Licensed User
Longtime User
In the Android version of my app, I use ViewBadger to put a badge on buttons.
Now I try to do the same in iOS.
I found this Objective C Class: http://latest.docs.nimbuskit.info/NIBadgeView.html

My question is: Can I use that class by importing the NimbusBadge.h from within an #IF OBJC block in B4i, define a wrapper in Objective C to set a badge on a view and then write a B4i Sub that wraps the Objective C wrapper method ?

Something like this:

B4X:
#IF OBJC
#import "NimbusBadge.h"

- (void) setBadgeViewInternal:(NSString*)txt :(UIColor*)bgColor :(UIView*)viewButton
{
NIBadgeView* badgeView = [[NIBadgeView alloc] initWithFrame:CGRectZero];
badgeView.text = txt;
badgeView.tintColor = bgColor;
[badgeView sizeToFit];
[viewButton addSubview:badgeView];
}

#END IF

Sub setBadgeView(txt As String, bgColor As Color, v As View)

Dim no As NativeObject = Me
no.RunMethod("setBadgeViewInternal:::", Array As Object(txt, no.ColorToUIColor(bgColor), v))

End Sub

And calling the B4i sub:

B4X:
Dim btn As Button
btn.Text = "Click Me"
setBadgeView("7", Colors.Blue, btn)

If this is possible, where do I place any .h and .m files of NimbusBadge so that they are included in my project ?
 
Last edited:
Top