iOS Question UIColorToColor not working

Alexander Stolte

Expert
Licensed User
Longtime User
I try the code from this thread:
B4X:
Dim NaObj As NativeObject = pnl
Dim BorderUIColor As Int = NaObj.UIColorToColor(NaObj.GetField("layer").GetField("borderColor"))
but i get this Error:
B4X:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Application_Active
Error occurred on line: 237 (ASSegmentedTab)
-[__NSCFType getRed:green:blue:alpha:]: unrecognized selector sent to instance 0x600003861a40
Stack Trace: (
  CoreFoundation       __exceptionPreprocess + 242
  libobjc.A.dylib      objc_exception_throw + 48
  CoreFoundation       +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
  CoreFoundation       ___forwarding___ + 1455
  CoreFoundation       _CF_forwarding_prep_0 + 120
  B4i Example          -[B4I UIColorToColor:] + 75
  B4i Example          -[B4INativeObject UIColorToColor:] + 97
  CoreFoundation       __invoking___ + 140
  CoreFoundation       -[NSInvocation invoke] + 305
  B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
 B4i Example          -[B4IShell runMethod:] + 401
 B4i Example          -[B4IShell raiseEventImpl:method:args::] + 1775
 B4i Example          -[B4IShellBI raiseEvent:event:params:] + 1357
 B4i Example          +[B4IDebug delegate:::] + 72
 B4i Example          -[b4i_assegmentedtab _setcircleclip:::] + 429
 B4i Example          -[b4i_assegmentedtab _base_resize:::] + 665
 CoreFoundation       __invoking___ + 140
 CoreFoundation       -[NSInvocation invoke] + 305
 B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
 B4i Example          -[B4IShell runMethod:] + 401
 B4i Example          -[B4IShell raiseEventImpl:method:args::] + 2361
 B4i Example          -[B4IShellBI raiseEvent:event:params:] + 1357
 B4i Example          +[B4IObjectWrapper raiseEvent:::] + 273
 B4i Example          __30-[B4IPanelView layoutSubviews]_block_invoke + 858
 libdispatch.dylib    _dispatch_call_block_and_release + 12
 libdispatch.dylib    _dispatch_client_callout + 8
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 1045
 CoreFoundation       __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
 CoreFoundation       __CFRunLoopRun + 2781
 CoreFoundation       CFRunLoopRunSpecific + 567
 GraphicsServices     GSEventRunModal + 139
 UIKitCore            -[UIApplication _run] + 912
 UIKitCore            UIApplicationMain + 101
 B4i Example          main + 112
 libdyld.dylib        start + 1
)
Output without UIColorToColor:
B4X:
<B4INativeObject: <CGColor 0x600003442dc0> [<CGColorSpace 0x6000034486c0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 1 1 1 )>
 

Semen Matusovskiy

Well-Known Member
Licensed User
Try to use uicolor initWithCGColor: method

B4X:
    ' *** Set border color ***
    Dim pnl As Panel
    pnl.Initialize ("")
    pnl.SetBorder (1, Colors.Magenta, 0)
    
    ' *** Get border color ***
    Dim noMe As NativeObject = Me
    Dim BorderUIColor As Int = noMe.UIColorToColor (noMe.RunMethod ("borderColor:", Array (pnl)))
    
    ' *** Test results ***
    If BorderUIColor = Colors.Magenta Then Log ("Magenta") Else Log ("not Magenta")
   
   ....
#If OBJC
- (UIColor *) borderColor: (UIView *) view { return [[UIColor alloc] initWithCGColor: view.layer.borderColor]; }
#End If
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…