xamarin - How to use a Custom iOS View(located in a referenced Class Library) in an Interface Builder file? -
i have 2 projects. first 1 ios-app referencing class library target framework xamarin.ios
. in class library implemented customview
inherits uiview
. registered "register"
attribute.
so in interface designer prefilled information use class custom class after dragged uiview
viewcontroller
. when run app following information:
"unknown class mycustomview in interface builder file."
if move customview
class library project first project run expected.
does know how use customview
, located in referenced class library, in interface builder file?
i don't think it's possible register
accross project boundaries. in tests, when use exact same namespace, still end error.
what is possible, on other hand, use proxy class , make use of inheritance bring desired behaviour proxy.
basically, boils down this:
1) in library, define custom uiview
, implement behaviour want share:
public class mycustomuiview : uiview { public mycustomuiview(intptr ptr) : base (ptr) { } public override void awakefromnib() { // beautiful here... addsubview(new uilabel(new cgrect(0,0,200,30)) { text = "i live in library"}); backgroundcolor = uicolor.green; } }
note don't register
this class, because won't work anyway.
2) in app project, open storyboard in interface designer or xcode , assign new name placeholder uiview
. in case, chose mycustomuiviewproxy
. xamarin studio create 2 files you: mycustomuiviewproxy.cs , mycustomuiviewproxy2.designer.cs. note in designer.cs file, xamarin automatically register
ed proxy class.
3) have use inheritance, make proxy act original: in mycustomuiviewproxy.cs, change base class uiview
mycustomuiview
, , we're go:
partial class mycustomuiviewproxy : mycustomuiview { public mycustomuiviewproxy (intptr handle) : base (handle) { } }
that's it:
Comments
Post a Comment