简体   繁体   中英

Pass Subview to subclassed UIView

I have a subclassed UIView with a special behavior.

It is a custom class of a ViewController xib view. It contains a subview, which is currently created programmatically.

My question is; how to pass a subview either from the xib or from one created programmatically in the viewController via initWithFrame or initWithCoder to my subclassed view? (Right now it simply acts through the view, not initiated at all in the VC.)

I would share code, but I don't know that it's necessary.

Use the initWithFrame method:

SubclassedView *view = [[SubclassedView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:view];

Be sure to import #import "SubclassedView.h"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM