I have a class called packages that creates a uiscrollview.
I have a getter for this class and once called, it returns a UIScroll view.
I would like my main application to set its scroll view to the one returned by the app. here is code that returns the scroll view:
MyClass.m
-(UIScrollView *)makeScrollView{
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
[self.scrollView setBackgroundColor:color];
[self.scrollView setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
[self.scrollView setPagingEnabled : NO];
[self.scrollView setCanCancelContentTouches:YES];
[self.scrollView setUserInteractionEnabled:YES];
self.scrollView.scrollEnabled = TRUE;
self.scrollView.bounces = TRUE;
self.scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
self.scrollView.userInteractionEnabled = YES;
CGFloat xOrigin = 0;
int numberOfViews = [self.pictureArray count];
// UIImageView *imageView1;
int i = 0;
for(NSString *item in self.pictureArray){
UIImageView *imageView1;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
tap.delegate = self;
xOrigin = i * imageSize;
imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin,50,100,50)];
imageView1.tag = i;
[imageView1 setUserInteractionEnabled:YES];
[imageView1 addGestureRecognizer:tap];
[imageView1 setImage:[UIImage imageNamed:item]];
[self.scrollView addSubview:imageView1];
i += 1;
}
// Set the contentSize equal to the size of the UIImageView
// scrollView.contentSize = imageView.scrollview.size;
self.scrollView.contentSize = CGSizeMake(numberOfViews * imageSize, 70);
return self.scrollView;
}
and its being set using a uipickerview selection inside of my ViewController:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSLog(@"Changing the scroll view");
self.scrollView = [self.packages[(int)row] makeScrollView];
}
I know the picker view is being called because I am getting the proper logging message. However, my ScrollView inside of my ViewController is not being set.
The above view, which I can access with self.scrollView is the view I need to change.
makeScrollView
method returns the scroll view to your controller ... this is asking becz u are doing similar to this i am not sure, if i get this question correctly – Shankar BS