按钮不会出现在scrollview中

时间:2011-03-22 06:43:16

标签: iphone uiscrollview uibutton

我为scrollview编写代码并在其上添加按钮,但按钮没有出现在scrollview中。 我的代码

tableProductScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(75, 442, 874, 208)];
tableProductScrollView.delegate=self;
[tableProductScrollView setBackgroundColor:[UIColor clearColor]];
[tableProductScrollView  setCanCancelContentTouches:YES];
tableProductScrollView .indicatorStyle = UIScrollViewIndicatorStyleBlack;
tableProductScrollView .pagingEnabled = YES;
tableProductScrollView.showsVerticalScrollIndicator = YES;
[tableProductScrollView setContentSize:CGSizeMake(1748,208)];
[tableProductScrollView setScrollEnabled:YES];
[self.view addSubview:tableProductScrollView];  

CGRect frameProduct1 = CGRectMake(85, 445, 142, 150);
tableProduct1Button = [UIButton buttonWithType:UIButtonTypeCustom];
tableProduct1Button.frame = frameProduct1;  
UIImage *imgProduct1= [UIImage imageNamed:@"product6-small.png"];       
[tableProduct1Button setImage:imgProduct1 forState:UIControlStateNormal];
tableProduct1Button.backgroundColor = [UIColor clearColor];
tableProduct1Button.highlighted = YES;
//---add the action handler and set current class as target---
[tableProduct1Button addTarget:self
                             action:@selector(homeButtonAction)
                   forControlEvents:UIControlEventTouchUpInside];
[tableProductScrollView addSubview: tableProduct1Button];
请给我一些建议。

2 个答案:

答案 0 :(得分:0)

也许:

  

UIButton * tableProduct1Button =   [UIButton的   buttonWithType:UIButtonTypeCustom];

答案 1 :(得分:0)

尝试使用某种颜色制作圆形矩形按钮,然后查看是否能够看到按钮或检查框架。或者尝试为突出显示的状态设置图像。

[tableProduct1Button setImage:image1 forState:UIControlStateHighlighted];
相关问题