iOS Question Assign a UIView to a B4IPanel

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

Just use AddView:

B4X:
    Dim NaObj As NativeObject = Me
    Dim V As View = NaObj.RunMethod("CreateView",Null)
    Page1.RootPanel.AddView(V,0,0,100,100)

#if OBJC

-(UIView*)CreateView{
    UIView *View = [[UIView alloc] init];
    View.backgroundColor = [UIColor redColor];
   
    return View;
}
#End If

Jan
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
No.

I have create a UIViewController with OBJC and passed it to b4ipage. Like

Dim p as page= nativepage

Everything is ok until I want to use the RootPanel of the page.

i need something like
Dim p as panel=nativeUIView
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Ahh ok.
You can do something like that:

B4X:
    Dim NaObj As NativeObject = Me
    NaObj = NaObj.RunMethod("CreateViewController",Null)
    Dim P As Page = NaObj
    Dim V As View = NaObj.GetField("view")
   
    Dim NaObj2 As NativeObject = Me
    Dim Top As Float = NaObj2.RunMethod("yOffset2:",Array(NavControl)).AsNumber
   
    If NavControl.NavigationBarVisible Then
        Top = Top + NaObj2.RunMethod("yOffset1:",Array(NavControl)).AsNumber
    End If
    Dim RootPanel As Panel
    RootPanel.Initialize("")
    RootPanel.SetLayoutAnimated(0,1,0,Top,V.Width,V.Height)
   
    NaObj = V
    NaObj.RunMethod("addSubview:",Array(RootPanel))
   
    NavControl.ShowPage(P)
   
    RootPanel.Color = Colors.Green
   
    'Now you can add views to the "RootPanel" (it's not the real root panel)
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text = "Hello"
    RootPanel.AddView(lbl,0,0,300,20)
   


#if OBJC

-(UIViewController *)CreateViewController{
    UIViewController *ViewController = [[UIViewController alloc] init];
    return ViewController;
}

-(CGFloat)yOffset1:(UINavigationController*)NC{
    return NC.navigationBar.frame.size.height;
}

-(CGFloat)yOffset2:(UINavigationController*)NC{
    return [[UIApplication sharedApplication] statusBarFrame].size.height;
}
#End If



Jan
 
Last edited:
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
In this
Ahh ok.
You can do something like that:

B4X:
    Dim NaObj As NativeObject = Me
    NaObj = NaObj.RunMethod("CreateViewController",Null)
    Dim P As Page = NaObj
    Dim V As View = NaObj.GetField("view")
      
    Dim RootPanel As Panel
    RootPanel.Initialize("")
    RootPanel.SetLayoutAnimated(0,1,0,0,V.Width,V.Height)
  
    NaObj = V
    NaObj.RunMethod("addSubview:",Array(RootPanel))
  
    NavControl.ShowPage(P)
  
    RootPanel.Color = Colors.Green



#if OBJC

-(UIViewController *)CreateViewController{
    UIViewController *ViewController = [[UIViewController alloc] init];
    return ViewController;
}
#End If

Jan


In this case I can not use it as panel to be able to add views to it )
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Yes, you can't use the RootPanel property of the new Page (because it's not a B4IViewController, so it doesn't have the mainView property). That's why I have added a RootPanel to the main view of the ViewController.
In short: Just add your views to "RootPanel" like above :)

Jan
 
Upvote 0
Top