iOS Question CSbuilder append image?

hongbii

Active Member
Licensed User
Longtime User
Hi all,
Anyone have any idea how the CSbuilder in B4i appends image?
If no, is that any possible ways to add an image in label?

Thank you.
 
Last edited:
SS-2017-07-16_12.44.45.png


Code:
Sub AppendImage(cs As CSBuilder, bmp As Bitmap)
   Dim attachment As NativeObject
   attachment = attachment.Initialize("NSTextAttachment").RunMethod("new", Null)
   attachment.SetField("image", bmp)
   Dim attributedString As NativeObject
   attributedString = attributedString.Initialize("NSAttributedString") _
     .RunMethod("attributedStringWithAttachment:", Array(attachment))
   Dim no As NativeObject = cs
   no.RunMethod("appendAttributedString:", Array(attributedString))
End Sub

Usage:
Code:
Dim cs As CSBuilder
cs.Initialize.Color(Colors.Red).Append("abc ")
AppendImage(cs, LoadBitmap(File.DirAssets, "smiley.png"))
cs.Append("a skjdlaj sdlkaj dlkas jdkl")
cs.PopAll
Label1.AttributedText = cs

Make sure that the image is not too large.
 
Upvote 0
Hi Erel,
Thank you for the solution,
It successfully appends an image in the label.
I have another question for the "NSTextAttachment",
In this case, is that possible to adjust the size for the image?
Is that something like:
Code:
attachment.RunMethod("bounds",Array(some parameters))
?
How to relate the CGRect(NSTextAttachment) type with array when dealing with NativeObject?
Can you teach me?
Thank you very much.
 
Upvote 0
Back
Top