iOS Question CSBuilder Size AppendImage

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
I need to change the size of an image in a button contained in a ScroollView.
I used:

B4X:
Dim cs1 As CSBuilder
                    cs1.Initialize
                    AppendImage(cs1, LoadBitmap(File.DirAssets, $"${m.Get("immagine")}"$))
                    cs1.Append(CRLF)
                    cs1.Color(Colors.White).Font(Font.CreateNewBold(10)).Append($"${m.Get("categoria")}"$)
                    cs1.PopAll

                    ButtonSetAttributedText(btnInside,cs1, cs1, cs1.Initialize.Append("disabled"))

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

Sub ButtonSetAttributedText(btn As Button, NormalText As AttributedString, HighlightedText As AttributedString, _
     DisabledText As AttributedString)
    Dim no As NativeObject = btn
    no.RunMethod("setAttributedTitle:forState:", Array(NormalText, 0))
    no.RunMethod("setAttributedTitle:forState:", Array(HighlightedText, 1))
    no.RunMethod("setAttributedTitle:forState:", Array(DisabledText, 2))
End Sub

if i have
attachment.MakeSize(30.0,30.0)

or this

attachment.MakeSize(80.0,80.0)

dont change nothing.
Any idea ?
Thank you
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
As this ( in attachment ) 100 x 100

20171213_152243.jpg
 

Attachments

  • elettricista.png
    elettricista.png
    4.3 KB · Views: 296
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
if i write:

B4X:
Sub AppendImage(cs As CSBuilder, bmp As Bitmap)
    Dim attachment As NativeObject
    attachment = attachment.Initialize("NSTextAttachment").RunMethod("new", Null)
    attachment.SetField("image", bmp )
    'attachment.SetField("bounds", attachment.MakeRect(0.0,0.0,80.0,80.0))
    attachment.SetField("bounds", attachment.MakeSize(80.0,80.0))
    Dim attributedString As NativeObject
    attributedString = attributedString.Initialize("NSAttributedString") _
     .RunMethod("attributedStringWithAttachment:", Array(attachment))
    Dim no As NativeObject = cs
    no.RunMethod("appendAttributedString:", Array(attributedString))
   

End Sub

i have this error:

Application_Start
Application_Active
JobName = categorie, Success = true
Response from server: [{"categoria":"IDRAULICO","immagine":"idraulico.png"},{"categoria":"ELETTRICISTA","immagine":"elettricista.png"},{"categoria":"IMBIANCHINO","immagine":"imbianchino.png"},{"categoria":"FALEGNAME","immagine":"falegname.png"},{"categoria":"MURATORE","immagine":"muratore.png"},{"categoria":"FABBRO","immagine":"fabbro.png"},{"categoria":"INFISSI E TAPPARELLE","immagine":"infissi.png"},{"categoria":"PULIZIE","immagine":"pulizie.png"},{"categoria":"GIARDINIERE","immagine":"giardiniere.png"},{"categoria":"TRASLOCO","immagine":"trasloco.png"},{"categoria":"ASSISTENZA ELETTRODOMESTICI","immagine":"assistenzaelettrodomestici.png"},{"categoria":"RISTRUTTURAZIONE","immagine":"ristrutturazione.png"},{"categoria":"BABY SITTER","immagine":"babysitter.png"},{"categoria":"COMMISSIONI FUORI CASA","immagine":"commissionifuoricasa.png"},{"categoria":"ARCHITETTO","immagine":"architetto.png"},{"categoria":"INGEGNERIA","immagine":"ingegnere.png"}]
Error occurred on line: 196 (Main)
-[_NSInlineData rectValue]: unrecognized selector sent to instance 0x17eb6b30
Stack Trace: (
CoreFoundation <redacted> + 152
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
CoreFoundation <redacted> + 696
CoreFoundation <redacted> + 24
Foundation <redacted> + 54
Foundation _NSSetUsingKeyValueSetter + 314
Foundation <redacted> + 236
B4i Pulsanti -[B4INativeObject SetField::] + 130
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Pulsanti +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B4i Pulsanti -[B4IShell runVoidMethod] + 204
B4i Pulsanti -[B4IShell raiseEventImpl:method:args::] + 2146
B4i Pulsanti -[B4IShellBI raiseEvent:event:params:] + 1578
B4i Pulsanti +[B4IDebug delegate:::] + 52
B4i Pulsanti -[b4i_main _appendimage::] + 580
B4i Pulsanti -[b4i_main _jobdone:] + 7750
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Pulsanti +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B4i Pulsanti -[B4IShell runMethod:] + 590
B4i Pulsanti -[B4IShell raiseEventImpl:method:args::] + 2238
B4i Pulsanti -[B4IShellBI raiseEvent:event:params:] + 1578
B4i Pulsanti -[B4ICommon CallSub4::::] + 332
B4i Pulsanti -[B4ICommon CallSub2::::] + 250
B4i Pulsanti -[b4i_httpjob _complete:] + 182
B4i Pulsanti -[b4i_httputils2service _completejob::::] + 344
B4i Pulsanti -[b4i_httputils2service _hc_responsesuccess::] + 130
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Pulsanti +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B4i Pulsanti -[B4I raiseEvent:event:params:] + 634
B4i Pulsanti __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 248
libdispatch.dylib <redacted> + 222
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 902
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 848
CoreFoundation CFRunLoopRunSpecific + 470
CoreFoundation CFRunLoopRunInMode + 104
GraphicsServices GSEventRunModal + 80
UIKit UIApplicationMain + 150
B4i Pulsanti main + 106
libdyld.dylib <redacted> + 2
)

The line 196 is:
attachment.SetField("bounds", attachment.MakeSize(80.0,80.0))

same thing if i use:
attachment.SetField("bounds", attachment.MakeRect(0.0,0.0,80.0,80.0))
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
B4X:
Sub AppendImage(cs As CSBuilder, bmp As Bitmap)
    Dim attachment As NativeObject
    attachment = attachment.Initialize("NSTextAttachment").RunMethod("new", Null)
    attachment.SetField("image", bmp )
    attachment.SetField("bounds", attachment.MakeRect(0.0,0.0,80.0,80.0))
    Dim attributedString As NativeObject
    attributedString = attributedString.Initialize("NSAttributedString") _
     .RunMethod("attributedStringWithAttachment:", Array(attachment))
    Dim no As NativeObject = cs
    no.RunMethod("appendAttributedString:", Array(attributedString))
End Sub

The error is:

Application_Start
Application_Active
JobName = categorie, Success = true
Response from server: [{"categoria":"IDRAULICO","immagine":"idraulico.png"},{"categoria":"ELETTRICISTA","immagine":"elettricista.png"},{"categoria":"IMBIANCHINO","immagine":"imbianchino.png"},{"categoria":"FALEGNAME","immagine":"falegname.png"},{"categoria":"MURATORE","immagine":"muratore.png"},{"categoria":"FABBRO","immagine":"fabbro.png"},{"categoria":"INFISSI E TAPPARELLE","immagine":"infissi.png"},{"categoria":"PULIZIE","immagine":"pulizie.png"},{"categoria":"GIARDINIERE","immagine":"giardiniere.png"},{"categoria":"TRASLOCO","immagine":"trasloco.png"},{"categoria":"ASSISTENZA ELETTRODOMESTICI","immagine":"assistenzaelettrodomestici.png"},{"categoria":"RISTRUTTURAZIONE","immagine":"ristrutturazione.png"},{"categoria":"BABY SITTER","immagine":"babysitter.png"},{"categoria":"COMMISSIONI FUORI CASA","immagine":"commissionifuoricasa.png"},{"categoria":"ARCHITETTO","immagine":"architetto.png"},{"categoria":"INGEGNERIA","immagine":"ingegnere.png"}]
Error occurred on line: 195 (Main)
-[_NSInlineData rectValue]: unrecognized selector sent to instance 0x14eb2c90
Stack Trace: (
CoreFoundation <redacted> + 152
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
CoreFoundation <redacted> + 696
CoreFoundation <redacted> + 24
Foundation <redacted> + 54
Foundation _NSSetUsingKeyValueSetter + 314
Foundation <redacted> + 236
B4i Pulsanti -[B4INativeObject SetField::] + 130
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Pulsanti +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B4i Pulsanti -[B4IShell runVoidMethod] + 204
B4i Pulsanti -[B4IShell raiseEventImpl:method:args::] + 2146
B4i Pulsanti -[B4IShellBI raiseEvent:event:params:] + 1578
B4i Pulsanti +[B4IDebug delegate:::] + 52
B4i Pulsanti -[b4i_main _appendimage::] + 580
B4i Pulsanti -[b4i_main _jobdone:] + 7750
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Pulsanti +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B4i Pulsanti -[B4IShell runMethod:] + 590
B4i Pulsanti -[B4IShell raiseEventImpl:method:args::] + 2238
B4i Pulsanti -[B4IShellBI raiseEvent:event:params:] + 1578
B4i Pulsanti -[B4ICommon CallSub4::::] + 332
B4i Pulsanti -[B4ICommon CallSub2::::] + 250
B4i Pulsanti -[b4i_httpjob _complete:] + 182
B4i Pulsanti -[b4i_httputils2service _completejob::::] + 344
B4i Pulsanti -[b4i_httputils2service _hc_responsesuccess::] + 130
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Pulsanti +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B4i Pulsanti -[B4I raiseEvent:event:params:] + 634
B4i Pulsanti __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 248
libdispatch.dylib <redacted> + 222
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 902
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 848
CoreFoundation CFRunLoopRunSpecific + 470
CoreFoundation CFRunLoopRunInMode + 104
GraphicsServices GSEventRunModal + 80
UIKit UIApplicationMain + 150
B4i Pulsanti main + 106
libdyld.dylib <redacted> + 2
)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This should have been the first post ;)

Correct code:
B4X:
Sub AppendImage(cs As CSBuilder, bmp As Bitmap)
   Dim attachment As NativeObject
   attachment = attachment.Initialize("NSTextAttachment").RunMethod("new", Null)
   attachment.SetField("image", bmp)
   Dim nme As NativeObject = Me
   'set bounds
   nme.RunMethod("SetBounds::", Array(attachment, attachment.MakeRect(0, 0, 50, 100)))
   Dim attributedString As NativeObject
   attributedString = attributedString.Initialize("NSAttributedString") _
     .RunMethod("attributedStringWithAttachment:", Array(attachment))
   Dim no As NativeObject = cs
   no.RunMethod("appendAttributedString:", Array(attributedString))
End Sub

#if OBJC
-(void)SetBounds:(NSTextAttachment*) attachment :(NSData*)data {
   attachment.bounds = *(CGRect*)data.bytes;
}
#End If
 
Upvote 0
Top