【发布时间】:2015-10-01 07:36:29
【问题描述】:
我有一个 ViewController,其中有一个 UIScrollView。在那我有一个 UIView 和 UIView 我必须添加标签和图像。图片应该在我的标签上方。
顺序为 Controller>>ScrollView>>UIView >> UILabel >> UIImageView
但我无法将 UIimageView 添加到视图中。
这是我的代码
scrollView =[[UIScrollView alloc]init];
[scrollView setFrame:CGRectMake(0, 0, 320, 480)];
[scrollView setContentSize:CGSizeMake(320,2820)];
[scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
[scrollView setScrollEnabled:YES];
[scrollView setShowsHorizontalScrollIndicator:YES];
[scrollView setShowsVerticalScrollIndicator:NO];
[self.view addSubview:scrollView];
UIView *firstView = [[UIView alloc]initWithFrame:CGRectMake(5, 5, 310, 300)];
firstView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:firstView];
UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(65, 3, 180, 50)];
label.text = @"ABC";
label.textAlignment =NSTextAlignmentCenter;
label.textColor = [UIColor colorWithRed:74.0/255.0 green:144.0/255.0 blue:226.0/255.0 alpha:1];
label.font=[UIFont fontWithName:@"Helvetica-Bold" size:18];
[firstView addSubview:label];
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(115, 0, 90, 90)];
imgView.image = [UIImage imageNamed:@"thumbs4.png"];
[self.view bringSubviewToFront:imgView];
[self.view bringSubviewToFront:imgView] 这行什么都不做
【问题讨论】:
-
试试:
[scrollView addSubview:imgView]; -
@TusharJ。 - 是的,它在添加到滚动视图后出现,但我希望它的框架是固定的。因为我不希望它被滚动
-
在我看来,理想的方法是将
imgView添加到self.view并使scrollView透明。但我认为,您正在为scrollView[scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];提供背景颜色。试试这个:[self.view addSubview:imgView]; [self.view bringSubviewToFront:imgView]; -
要将超级视图的子视图放在前面,首先必须将其添加到超级视图中。
-
@TusharJ。 - 谢谢好友
标签: ios objective-c iphone uiimageview