如何与多个目标c类共享xib文件

发布于 2025-01-06 08:57:00 字数 91 浏览 4 评论 0原文

我是ios开发的新手,所以我不知道这个问题是否正确。 我想在基于视图的应用程序模板中从单独的 uiview 类创建 uibutton 。 如果有人知道,请澄清我的问题。

I am new in ios development, so i don't know this question is correct or not.
I want to create a uibutton from a separate uiview class in view based application template.
if anybody know ,please clear my question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北音执念 2025-01-13 08:57:00

这很容易做到。这段代码片段应该有帮助;

    NSArray* nibRollViews = [[NSBundle mainBundle] loadNibNamed:@"TiltData" owner:self options:nil];
    myRollDataView = [nibRollViews lastObject]; // TODO, look it up by name, don't assume last

    [myRollDataView setFrame:CGRectMake(rollDataViewFPO.frame.origin.x, 
                                    rollDataViewFPO.frame.origin.y, 
                                    myRollDataView.frame.size.width, 
                                    myRollDataView.frame.size.height)];
    [self.view addSubview:myRollDataView];
    [myRollDataView initWithType:RollType];

有几点需要注意。我的 xib 中有一个 rollDataViewFPO(FPO 的意思是“仅用于位置”)。我使用 FPO 框架来定位刚刚加载的对象。这样我就可以将它定位在我的 xib 上,而不是我的代码上。

另请注意,我调用了自己的 initWithType 方法。我的 TiltData 对象可用于显示滚动或俯仰数据,我需要告诉它们它们是什么类型。

That's pretty easy to do. This code snippet should help;

    NSArray* nibRollViews = [[NSBundle mainBundle] loadNibNamed:@"TiltData" owner:self options:nil];
    myRollDataView = [nibRollViews lastObject]; // TODO, look it up by name, don't assume last

    [myRollDataView setFrame:CGRectMake(rollDataViewFPO.frame.origin.x, 
                                    rollDataViewFPO.frame.origin.y, 
                                    myRollDataView.frame.size.width, 
                                    myRollDataView.frame.size.height)];
    [self.view addSubview:myRollDataView];
    [myRollDataView initWithType:RollType];

There are a few things to note. I have a rollDataViewFPO (FPO means "for position only") in my xib. I use the FPO frame for positioning the object I just loaded. This way I can position it my xib, not my code.

Also note that I call my own initWithType method. My TiltData objects can be used to show Roll or Pitch data, and I need to tell them what type they are.

遗失的美好 2025-01-13 08:57:00

添加一个新的File ObjectiveC类,使其成为UIView的子类(此处假设名称:SubView)。

如果您不想使用 UIViewController 类的视图,则只需在

UiViewController 的 xib 中选择视图,然后在检查器窗口中将类名称更改为 SubView。将 UIButton

放入该视图中并执行您想要的任何操作。如果您想要单独View 然后只需

从菜单栏中拖放 UIView 并将其作为出口连接到 ViewController 类,并将

UIView 类的名称更改为 SubView。

Add a newFile ObjectiveC class make it as SubClass of UIView(assume name here: SubView).

if you doesn't want to use the view of UIViewController Class then just select the view in xib

of UiViewController and change the class name to SubView in inspector window.put the UIButton

in that view and do anything what you want.If you want Separate View then simply drag and

drop UIView from menu bar and connect that as an outlet to your ViewController Class and

change name of UIView class to SubView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文