iOS Question Add outline to text

Erel

B4X founder
Staff member
Licensed User
Longtime 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)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…