如何添加scrollView以进行垂直滚动以及标签

时间:2013-02-15 05:25:29

标签: iphone ipad uiscrollview uilabel

我想添加带标签的UIScrollView并使其滚动垂直如果我有更多标签我正在添加以下代码但它不滚动。我还有5个标签可供添加。

在页眉文件中

IBOutlet UIScrollView*scrollView;


    @property(nonatomic,retain) IBOutlet UIScrollView*scrollView;

在viewDidLoad

中的实现文件中
     titleLabel = [[UILabel alloc ] initWithFrame:CGRectMake(892,257,206,84)];
 titleLabel.textAlignment =  UITextAlignmentRight;
 titleLabel.textColor = [UIColor blackColor];
 titleLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
 [scrollView addSubview:titleLabel];


titleLabel = [[UILabel alloc ] initWithFrame:CGRectMake(10,20,206,84)];
titleLabel.textAlignment =  UITextAlignmentRight;
titleLabel.textColor = [UIColor blackColor];
titleLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
[scrollView addSubview:titleLabel];


titleLabel1 = [[UILabel alloc ] initWithFrame:CGRectMake(10,110,206,84)];
titleLabel1.textAlignment =  UITextAlignmentRight;
titleLabel1.textColor = [UIColor blackColor];
titleLabel1.font = [UIFont fontWithName:@"Helvetica" size:14];
titleLabel1.text=@"tilte Working Fine";

[scrollView addSubview:titleLabel1];


titleLabel2 = [[UILabel alloc ] initWithFrame:CGRectMake(10,190,206,84)];
titleLabel2.textAlignment =  UITextAlignmentRight;
titleLabel2.textColor = [UIColor blackColor];
titleLabel2.text=@"tilte Working Fine";
titleLabel2.font = [UIFont fontWithName:@"Helvetica" size:14];
[scrollView addSubview:titleLabel2];




titleLabel3 = [[UILabel alloc ] initWithFrame:CGRectMake(10,270,206,84)];
titleLabel3.textAlignment =  UITextAlignmentRight;
titleLabel3.textColor = [UIColor blackColor];
titleLabel3.font = [UIFont fontWithName:@"Helvetica" size:14];
titleLabel3.text=@"tilte Working Fine";

[scrollView addSubview:titleLabel3];


titleLabel4 = [[UILabel alloc ] initWithFrame:CGRectMake(10,360,206,84)];
titleLabel4.textAlignment =  UITextAlignmentRight;
titleLabel4.textColor = [UIColor blackColor];
titleLabel4.font = [UIFont fontWithName:@"Helvetica" size:14];
titleLabel4.text=@"tilte Working Fine";

[scrollView addSubview:titleLabel4];



titleLabel5 = [[UILabel alloc ] initWithFrame:CGRectMake(10,450,206,84)];
titleLabel5.textAlignment =  UITextAlignmentRight;
titleLabel5.textColor = [UIColor blackColor];
titleLabel5.font = [UIFont fontWithName:@"Helvetica" size:14];
titleLabel5.text=@"tilte Working Fine";

[scrollView addSubview:titleLabel5];


titleLabel6 = [[UILabel alloc ] initWithFrame:CGRectMake(10,530,206,84)];
titleLabel6.textAlignment =  UITextAlignmentRight;
titleLabel6.text=@"tilte Working Fine";

titleLabel6.textColor = [UIColor blackColor];
titleLabel6.font = [UIFont fontWithName:@"Helvetica" size:14];
[scrollView addSubview:titleLabel6];

1 个答案:

答案 0 :(得分:0)

如果内容大小超过帧大小,则需要增加滚动视图的内容大小与其帧大小不同。