iOS Question Add outline to text

Erel

Administrator
Staff member
Licensed User


B4X:
Sub CreateOutlineText(Text As String, StrokeColor As Int, ForegroundColor As Int, Fnt As Font) As AttributedString
   Dim no As NativeObject = Me
   Return no.RunMethod("CreateOutlineText::::", Array(Text, no.ColorToUIColor(StrokeColor), no.ColorToUIColor(ForegroundColor), Fnt))
End Sub


#if OBJC
- (NSAttributedString*) CreateOutlineText:(NSString*) Text :(UIColor*)StrokeColor :(UIColor*)ForegroundColor :(UIFont*)Font {
   return [[NSAttributedString alloc]initWithString:Text attributes:
       @{NSStrokeColorAttributeName : StrokeColor, NSForegroundColorAttributeName: ForegroundColor,
       NSStrokeWidthAttributeName:@(-4.0), NSFontAttributeName: Font}];
}
#End If
Usage:
B4X:
Label1.AttributedText = CreateOutlineText("This is a test", Colors.Red, Colors.Yellow, Label1.Font)
 
Top