【发布时间】:2012-09-26 11:08:27
【问题描述】:
我在情节提要中有一个 UIViewController,其中包含一个滚动视图。
我想在上面放两个 UIImageView 和一些 UILabel。
我的想法是:创建一个 .xib 文件。在上面放一个 UIView,然后在这个 UIView 上设置我的 UIImageview 和标签。
最后将我的 UIView 这是一个 .xib 文件添加到我的 UIScrollView 中,如下所示:
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"OfferView" owner:self options:nil];
UIView *newPageView = [views lastObject];
self.newPageView.contentMode = UIViewContentModeScaleAspectFill;
newPageView.frame = frame;
[self.scrollView addSubview:newPageView];
[self.pageViews replaceObjectAtIndex:page withObject:newPageView];
现在我想在我的 UIViewController 中以编程方式为 UIView 上的控件设置文本和图像。我尝试了这个,但它不起作用:
OfferUIView *offer2 = [[OfferUIView alloc] init];;
offer2.labelCompany.text = @"some text";
我也在ViewController的接口中定义了OfferUIView,然后同步,但也没有用:
@property (nonatomic, assign) OfferUIView *offerView;
你能帮帮我吗?
【问题讨论】:
-
为什么不在情节提要中布局内容,以便您可以轻松地将视图连接到视图控制器中的插座?
-
因为我想在我的scrollView中添加一个UIView,我无法在storyboard中单独创建一个UIView,所以我使用.xib文件。如果您认为这不是一个好方法,请为我写一个完整的答案,我会看看它。
标签: iphone objective-c ios xcode