[英]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.scrollView
和self.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.