简体   繁体   English

将我的UIView添加到Storyboard中的ViewController

[英]Add my UIView to a ViewController in Storyboard

I am new in iPhone development. 我是iPhone开发的新手。

I have a UIViewController in storyboard that includes a scrollView. 我在情节提要中有一个UIViewController,其中包括一个scrollView。

I want to put two UIImageViews and some UILabels on it. 我想在上面放两个UIImageViews和一些UILabel。

the idea that I am thinking is : create a .xib file. 我在想的想法是:创建一个.xib文件。 Put a UIView on it, an then set my UIImageview and labels on this UIView. 在上面放一个UIView,然后在此UIView上设置我的UIImageview和标签。

Finally add my UIView which is a .xib file to my UIScrollView. 最后,将.xib文件的UIView添加到UIScrollView中。

Is it a good idea? 这是个好主意吗? if not what is your suggestion. 如果不是,您的建议是什么。

until now I could not make it works. 到现在为止,我无法使它起作用。 this is my code: 这是我的代码:

OfferUIView *newPageView = [[OfferUIView alloc] init];      // UIView that I created as .xib
self.newPageView.contentMode = UIViewContentModeScaleAspectFill;
newPageView.frame = frame;
[self.scrollView addSubview:newPageView];
[self.pageViews replaceObjectAtIndex:page withObject:newPageView];

Can you help me? 你能帮助我吗?

我知道这听起来很愚蠢,但是您是否尝试self.scrollViewself.pageViews删除self

How did you created your .xib file? 您是如何创建.xib文件的? it should be sub class of UIView . 它应该是UIView的子类。 Hope you didn't do the mistake of creating it as a sub class of UIViewController. 希望您没有犯错将其创建为UIViewController的子类。

I found the answer: 我找到了答案:

NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"OfferView" owner:self options:nil];
UIView *newPageView = [views lastObject];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在我的情节提要ViewController中添加一个重新启动按钮以链接到其自身 - Add a restart button to my storyboard viewcontroller to link to its self 使用StoryBoard将“全局” UIView添加到应用程序 - Add a 'global' UIView to an App with StoryBoard 如何使用情节提要在tabBarViewcontroller顶部添加ViewController? - How to add ViewController on top of tabBarViewcontroller using storyboard? 如何在情节提要中向ViewController添加两个UITableViews? - How to add two UITableViews to ViewController in storyboard? 以编程方式将UIButton添加到自定义ViewController的情节提要 - Programmatically add UIButton to custom ViewController with storyboard in place 如何将自定义UIView添加到故事板场景 - How add a custom UIView to a storyboard scene 如何在ViewController及其NavigationController上添加UIview - How to add UIview over a ViewController and its NavigationController 重复使用带有故事板的xib(将UIView添加到UINavigationcontroller) - Reused xib with storyboard (add UIView to UINavigationcontroller) 快速编程-情节提要如何在ViewController上添加更多按钮 - swift programming - storyboard how to add more buttons on a viewcontroller 在一个Viewcontroller中具有多个UIView的Xcode Storyboard不允许在后台视图中移动项目 - Xcode Storyboard with multiple UIView in one Viewcontroller not allowing to move items in background view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM