[英]how to make text appear on multiple views with one label?
I'm using a scroll view with 3 views, and I need to place one label that shows up on each view, 我正在使用具有3个视图的滚动视图,并且需要在每个视图上放置一个标签,
the views are on separate view controllers: in view controller.h 视图在单独的视图控制器上:在view controller.h中
#import "PagerViewController.h"
@interface ViewController : PagerViewController {
}
@property (strong, nonatomic) IBOutlet UIView *View1;
@property (strong, nonatomic) IBOutlet UIView *View2;
@property (strong, nonatomic) IBOutlet UIView *View3;
I've placed them as (in ViewController.m) 我将它们放置为(在ViewController.m中)
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View1"]];
Should I fix an NSString and Outlet to do this? 我应该修复NSString和Outlet来做到这一点吗?
I need the labels to move with the scroll not to be separate from each other. 我需要标签与滚动条一起移动,以免彼此分开。
如果您需要分离这些视图,那么一种易于维护的解决方案可以是三个分离的标签和一个函数(updateLabels :),其中三个标签被更新为相同的值。
What you want, cannot be done with a single UILabel
. 您想要的,不能用单个
UILabel
。 You will have to create 3 separate labels and write the logic that will update all of them. 您将必须创建3个独立的标签,并编写将更新所有标签的逻辑。
Create the UILabel
outlets and write a method something similar to the method below: 创建
UILabel
出口,并编写类似于以下方法的方法:
- (void)updateLabels:(NSString *)text
{
self.label1.text = text;
self.label2.text = text;
self.label3.text = text;
}
This is just the way UIView
's work and you cannot make them draw outside of their bounds. 这只是
UIView
的工作方式,您不能使它们在其范围之外绘制。
I suggest you follow up on more iOS basics before going into complex layouts. 我建议您先进入更多iOS基础知识,然后再进行复杂的布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.