I'm using Storyboards, and I've created a UIScrollView and its outlet:
.h
@interface ViewController : UIViewController <UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@end
.m
: I synthesized scrollView, and on viewDidLoad i have
- (void)viewDidLoad {
[super viewDidLoad];
self.scrollView.delegate = self;
// Init an array with 3 images
subviewArray = [[NSMutableArray alloc] initWithObjects:@"image1.jpg", @"image2.jpg", @"image3.jpg", nil];
for (int i = 0; i < [subviewArray count]; i++) {
//We'll create a View object in every 'page' of our scrollView.
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = [UIImage imageNamed:[subviewArray objectAtIndex:i]];
[self.scrollView addSubview:imageView];
}
NSLog(@"%f", self.scrollView.frame.size.width);
//Set the content size of our scrollview according to the total width of our imageView objects.
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [subviewArray count], self.scrollView.frame.size.height);
}
The problem is when i print the value of "self.scrollView.frame.size.width" i get "0" ! Any help plz !!!
Fix it, i had to uncheck "use AutoLayout" in file inspector. Thanks a lot Wain ! Hope this could help anyone else. Good luck !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.