iOS Question Add outline to text

Dimper

Member
Licensed User
How can I add an outline to the label text?
I found the answer in swift:

https://stackoverflow.com/questions/40575408/outline-uilabel-text-in-uilabel-subclass

http://mabdev.com/2016/06/09/how-to-outline-your-uilabel-uibutton/

screen-shot-2016-06-09-at-1-32-07-pm-300x113.png
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4i_1C6NkG5G8W.png


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
Top