I am write code for scrollview and add button on it but button not appear in scrollview. My code
tableProductScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(75, 442, 874, 208)];
tableProductScrollView.delegate=self;
[tableProductScrollView setBackgroundColor:[UIColor clearColor]];
[tableProductScrollView setCanCancelContentTouches:YES];
tableProductScrollView .indicat开发者_Go百科orStyle = 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];
please give me suggestion.
maybe:
UIButton *tableProduct1Button = [UIButton buttonWithType:UIButtonTypeCustom];
Try to make a round rect button with some color and then see if you are able to see the button or else check the frame. Or try to set an image for the highlighted state.
[tableProduct1Button setImage:image1 forState:UIControlStateHighlighted];
精彩评论