So apparently I'm adding the same label over and over. I have an IBOutlet for UILabel that I hooked up in IB. I did that because that's the position I want it in for my UIScrollView. I also want a new label on each page in my ScrollView but I can't figure out how to do it.
Any suggestions for how to accomplish this? Because I'm lost :-/
AnotherMadeUpViewController.h
#import <UIKit/UIKit.h>
#interface AnotherMadeUpViewController : UIViewController<UIScrollViewDelegate>
{
IBOutlet UIPageControl *pageControl;
IBOutlet UIScrollView *scroller;
IBOutlet UILabel *label;
}
#property (nonatomic,retain)IBOutlet UIPageControl *pageControl;
#property (nonatomic,retain)IBOutlet UIScrollView *scroller;
#property (nonatomic,retain)IBOutlet UILabel *label;
-(IBAction)clickPageControl:(id)sender;
#end
AnotherMadeUpViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
scroller.delegate=self;
scroller.pagingEnabled=YES;
scroller.directionalLockEnabled=YES;
scroller.showsHorizontalScrollIndicator=NO;
scroller.showsVerticalScrollIndicator=NO;
scroller.contentSize=CGSizeMake(pageControl.numberOfPages*scroller.frame.size.width, scroller.frame.size.height);
CGFloat labelOriginX = label.frame.origin.x;
CGFloat labelOriginY = label.frame.origin.y;
CGFloat scrollWidth = 0;
int pageNumber = 0;
for (int i=0; i<3; i++)
{
CGRect rect = label.frame;
rect.size.height = label.frame.size.height;
rect.size.width = label.frame.size.width;
rect.origin.x = labelOriginX + scrollWidth;
rect.origin.y = labelOriginY;
label.frame = rect;
label.text = [NSString stringWithFormat:#"%d", pageNumber];
label.textColor = [UIColor redColor];
[scroller addSubview:label];
pageNumber++;
scrollWidth += scroller.frame.size.width;
}
pageControl.numberOfPages=3;
pageControl.currentPage=0;
[self.view addSubview:scroller];
}
You are re-adding the same UILabel instance over and over then, nothing happens other than changing the label's location (frame) in the scrollView's contentView. You'd have to add 8 copies of that label to the scrollView, each in a different frame. If you want to tile an image in the scrollView's background, try setting its backgroundColor to a pattern image created with +[UIColor colorWithPatternImage: ]
Related
I have a custom UIView XIB that gets loaded onto my ViewController and the frame is adjusted to be collapsed before added to subview. The UIButton tied to my XIB is showing when the frame is smaller than the button location. How can I hide and show my UIButton as the frame is expanding/collapsing? My XIB is not using AutoLayout.
ViewController.m
self.greenView = [[[NSBundle mainBundle] loadNibNamed:#"Green" owner:self options:nil] objectAtIndex:0];
[self.navigationController.view addSubview:self.greenView];
GreenView.h
#interface GreenView : UIView
#property (weak, nonatomic) IBOutlet UIView *expandView;
#property (nonatomic, getter = isExpanded) BOOL expand;
#property (weak, nonatomic) IBOutlet UIButton *testButton;
- (IBAction)testButtonTapped:(id)sender;
#end
GreenView.m
#interface GreenView()
#property (nonatomic) UITapGestureRecognizer *tapGesture;
#end
#implementation GreenView
- (void)awakeFromNib {
CGRect frame = self.frame;
frame.size.height = self.expandView.frame.size.height;
frame.origin.y = 200;
self.frame = frame;
self.expand = NO;
[self.expandView addGestureRecognizer:self.tapGesture];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (UITapGestureRecognizer *)tapGesture {
if (!_tapGesture) {
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapClicked:)];
}
return _tapGesture;
}
- (void)tapClicked:(UIGestureRecognizer *)recognizer {
CGRect frame = self.frame;
self.expand = !self.expand;
frame.size.height = self.expand ? gvExpandedHeight : gvCollapsedHeight;
[UIView animateWithDuration:0.5 animations:^{
self.frame = frame;
} completion:^(BOOL finished) {
NSLog(#"Frame after animation: %#", NSStringFromCGRect(self.frame));
}];
}
- (IBAction)testButtonTapped:(id)sender {
NSLog(#"Test button tapped");
}
#end
Collapsed:
Expanded:
GreenView.xib:
GrenenView.xib Struts and Springs:
If I understood you just want to clip it, if the button is outside to the view bounds. In -awakeFromNib add:
self.clipsToBounds = YES;
Using this property you are telling the view to cut everything that is not inside its bounds, views caw draw subviews even if they are place outside. Is a little expensive by means of performance, if you use it a lot or during heavy animations.
One way around could be hide it while the view is collapsed.
You change the frame to frame.origin.y = 200;
I think you have to set the UIButton constraint relative to your GreenView in you nib file
The Problem
I have a UILabel buried in a few layers of subviews and I can't seem to change it's text. The code to update the label is inMyCardSubclass's updateVisualElements method. The really weird thing is that when I log the description of these labels, the text has been updated, but it is not visible. Here's what it looks like:
Inside my View Controller's viewDidLoad method I initialize a UIScrollView and my card object. I add its cardView as a subview like so:
-(void)viewDidLoad
{
[super viewDidLoad];
MyCardSubclass *myCard = [[MyCardSubclass alloc]initWithInfo:info andPoint:CGPointMake(5, runningYValue)];
[myCard setParentViewController:self];
[scrollView addSubview:[myCard cardView]];
//Resize scrollView contentSize
}
My Card
//header
#property (nonatomic, strong) UIView *contentView;
#property (nonatomic, strong) UIView *cardView;
#property (nonatomic, strong) CardInfo *cardInfo;
#property (nonatomic, strong) UIViewController *parentViewController;
//implementaion
-(UIView *)cardView
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIView *toReturn = [[UIView alloc]initWithFrame:CGRectMake(self.point.x,self.point.y, screenRect.size.width-borderOffset*2, cardViewHeight)];
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(borderOffset, 0, toReturn.frame.size.width-borderOffset*2, titleHeight)];
[titleLabel setText:self.title];
[toReturn addSubview:titleLabel];
[self.contentView setFrame:CGRectMake(borderOffset, titleHeight, screenRect.size.width-borderOffset, contentViewHeight)];
if(self.contentView)
[toReturn addSubview:self.contentView];
else
NSLog(#"no contentView");
//other view stuff
return toReturn;
}
My Card Subclass
//header
#property(nonatomic, strong) UILabel *totalAmountLabel;
#property(nonatomic, strong) UILabel *availableAmountLabel;
#property(nonatomic, assign) double available;
//implementation
-(UIView *)cardView
{
[self setContentView:[self contentViewFromCardInfo:self.cardInfo]];
return [super cardView];
}
-(UIView *)contentViewFromCardInfo:(CardInfo *)cardInfo
{
UIView *toReturn = [[UIView alloc]init];
NSString *amount = #"0";
self.totalAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(labelWidth,
runningYValue,
labelWidth,
labelHeight)];
[self.totalAmountLabel setText:amount];
[toReturn addSubview:self.totalAmountLabel];
runningYValue +=self.totalAmountLabel.frame.size.height+spacer;
self.availableAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(labelWidth,
runningYValue,
labelWidth,
labelHeight)];
[self.availableAmountLabel setText:#"0"];
[toReturn addSubview:self.availableAmountLabel];
return toReturn;
}
-(void)updateVisualElements
{
NSString *amount = #"10"
NSString *availableString = #100"
//The log descriptions for these labels are okay.
[self.totalAmountLabel setText:amount];
NSLog(#"%#",self.totalAmountLabel.debugDescription);
[self.availableAmountLabel setText:availableString];
NSLog(#"%#",self.availableAmountLabel.debugDescription);
NSAssert([NSThread isMainThread], #"Not on main thread");
NSAssert(self.totalAmountLabel, #"No label");
}
What I've tried
Calling [self.totalAmountLabel setNeedsDisplay] after setting the text
Calling the method on the main thread using [self.totalAmountLabel performSelector:#selector(setText:) withObject:amount afterDelay:0.0]
You can try one thing, Use Tag property to get the added Label and change its contends
Example:
UILabel totalAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(labelWidth,
runningYValue,
labelWidth,
[totalAmountLabel setText:amount];
totalAmountLabel.tag = 100;
[toReturn addSubview:totalAmountLabel];
Then in your updateVisualElements()
UILabel *tempTotalAmountLabel = (UILabel *)[self.view viewWithTag:100];
[tempTotalAmountLabel setText:amount];
Fixed it! The problem wasn't actually in my attempts to set the label or draw its view.
I wasn't using my initializers properly to init my content view only once.
I removed this override in my subclass
-(UIView *)cardView
{
[self setContentView:[self contentViewFromCardInfo:self.cardInfo]];
return [super cardView];
}
I also took the code from the -(UIView *)cardView method in my superclass and put into a -(UIView *)buildCardView method and rewrote the cardView property accessor to what it should have been.
-(UIView *)cardView
{
if(!_cardView)
_cardView = [self buildCardView];
return _cardView;
}
Thanks for the views and comments.
I'm not sure why, but I'm having trouble passing a data object (NSManagedObject) to a view controller when that view controller is being instantiated inside another one. When I log the object before it is passed, it has all of its data, but after it gets to the view controller, it is empty. It seems like this should be fairly straight-forward, but for some reason it's just not getting there.
The code which assigns the NSManagedObject to the accepting view controller in the implementation file is: viewController.thisCard = aCard;
Any help is much appreciated. Thanks in advance.
This is the header for the view controller which scrolls:
#interface HandViewController : UIViewController
<UIScrollViewDelegate>
{
IBOutlet UIScrollView *scrollView;
IBOutlet UIPageControl *pageControl;
BOOL pageControlIsChangingPage;
NSManagedObjectContext *context;
}
#property (nonatomic, retain) UIView *scrollView;
#property (nonatomic, retain) UIPageControl *pageControl;
#property (nonatomic, retain) NSManagedObjectContext *context;
/* for pageControl */
- (IBAction)changePage:(id)sender;
#end
this is the viewDidLoad in the implementation of that object
- (void)viewDidLoad
{
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Game" inManagedObjectContext:[self context]];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *fetchedGames = [self.context executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
Game *aGame = [fetchedGames objectAtIndex:0];
CGFloat cx = 0;
for (Card *aCard in aGame.turnUpcoming.hand) {
CardViewController *viewController = [[CardViewController alloc] initWithNibName:#"CardViewController" bundle:nil];
CGRect rect = self.view.frame;
rect.size.height = scrollView.frame.size.height - 50;
rect.size.width = scrollView.frame.size.width - 50;
rect.origin.x = ((scrollView.frame.size.width - rect.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - rect.size.height) / 2);
viewController.view.frame = rect;
viewController.thisCard = aCard;
[scrollView addSubview:viewController.view];
cx += scrollView.frame.size.width;
[viewController release];
}
self.pageControl.numberOfPages = [aGame.turnUpcoming.hand count];
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
UPDATE: Per request, I am adding a bit of code from the view controller
This is the header for CardViewController
#interface CardViewController : UIViewController {
UILabel IBOutlet *cardValue;
UILabel IBOutlet *cardInstruction;
UILabel IBOutlet *cardHint;
UILabel IBOutlet *cardTimer;
UIButton IBOutlet *playCardButton;
Card *thisCard;
}
#property (nonatomic, retain) UILabel IBOutlet *cardValue;
#property (nonatomic, retain) UILabel IBOutlet *cardInstruction;
#property (nonatomic, retain) UILabel IBOutlet *cardHint;
#property (nonatomic, retain) UILabel IBOutlet *cardTimer;
#property (nonatomic, retain) UIButton IBOutlet *playCardButton;
#property (nonatomic, retain) Card *thisCard;
#end
Here is the viewDidLoad from the implementation of CardViewController
- (void)viewDidLoad
{
[super viewDidLoad];
if ([thisCard isObjectValid]) {
cardValue.text = [thisCard.value stringValue];
}
}
UPDATE: new code for card loop in viewDidLoad and new CardView code, per suggestions below
loop in viewDidLoad:
for (Card *aCard in aGame.turnUpcoming.hand) {
CGRect rect = scrollView.frame;
rect.size.height = scrollView.frame.size.height - 50;
rect.size.width = scrollView.frame.size.width - 50;
rect.origin.x = ((scrollView.frame.size.width - rect.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - rect.size.height) / 2);
tempCardView = [[CardView alloc] initWithFrame:rect];
tempCardView.thisCard = aCard;
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"CardView" owner:self options:nil];
tempCardView = [nibObjects objectAtIndex:0];
[scrollView addSubview:tempCardView];
cx += scrollView.frame.size.width;
[tempCardView release];
}
header file CardView.h
#interface CardView : UIView {
UILabel IBOutlet *cardValue;
UILabel IBOutlet *cardInstruction;
UILabel IBOutlet *cardHint;
UILabel IBOutlet *cardTimer;
UIButton IBOutlet *playCardButton;
Card *thisCard;
}
#property (nonatomic, retain) UILabel IBOutlet *cardValue;
#property (nonatomic, retain) UILabel IBOutlet *cardInstruction;
#property (nonatomic, retain) UILabel IBOutlet *cardHint;
#property (nonatomic, retain) UILabel IBOutlet *cardTimer;
#property (nonatomic, retain) UIButton IBOutlet *playCardButton;
#property (nonatomic, retain) Card *thisCard;
#end
implementation file CardView.m
#implementation CardView
#synthesize cardHint;
#synthesize cardTimer;
#synthesize cardValue;
#synthesize cardInstruction;
#synthesize playCardButton;
#synthesize thisCard;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
if ([thisCard isObjectValid]) {
cardValue.text = [thisCard.value stringValue];
cardInstruction.text = thisCard.instruction;
cardHint.text = thisCard.hint;
cardTimer.text = [thisCard.time stringValue];
}
}
return self;
}
#end
UPDATED: 6/16 - Added XIB screen shot
CardView.xib
Seems like your CardViewController should actually be a UIView. As Apple says: " A single view controller typically manages the views associated with a single screen’s worth of content, although in iPad applications this may not always be the case."
(After changes to UIView) in your loop, you're creating one tempCard and then loading another. If you've linked tempCardView in IB (see below), then all you need is:
for (Card *aCard in aGame.turnUpcoming.hand) {
CGRect rect;
rect.size.width = scrollView.frame.size.width - 50;
rect.size.height = scrollView.frame.size.height - 50;
rect.origin.x = ((scrollView.frame.size.width - rect.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - rect.size.height) / 2);
[[NSBundle mainBundle] loadNibNamed:#"CardView" owner:self options:nil]; //magically connected to tempCardView.
self.tempCardView.frame = rect;
self.tempCardView.thisCard = aCard;
[scrollView addSubview:tempCardView];
cx += scrollView.frame.size.width;
self.tempCardView = nil;
}
So, you have two XIBs, your main one that loads with your viewController, and one (CardView) that gets loaded once for each card.
Now, inside CardView, you're trying to set up the labels too soon. During initWithFrame (which in the above case is called by loadFromNib), you don't have access yet to thisCard. You'll need a setter for thisCard, which will be called any time a value is assigned to thisCard property:
-(void) setThisCard: (Card *) newCard {
if (thisCard == newCard) return;
[newCard retain];
[thisCard release];
thisCard = newCard;
self.cardValue.text = [thisCard.value stringValue];
self.cardInstruction.text = thisCard.instruction;
self.cardHint.text = thisCard.hint;
self.cardTimer.text = [thisCard.time stringValue];
}
Now in Interface Builder,
Create CardView.xib with a single UIView with, but set FileOwner to your VC, NOT to CardView because that's who's going to load it (and who has the tempCardView property).
Set the view's type to CardView, then hook it to thetempCardView property of FileOwner (aka HandViewController)
Put all your other card parts inside that CardView and hook them up to that CardView's properties.
You should be all set.
Given the multitasking of iOS I thought it wouldn't be a pain to pause and resume my app, by pressing the home button or due to a phone call, but for a particular view controller it crashes.
The navigation bar is working fine i.e. when I tap "Back" it's ok, but if I try to tap controls of the displayed UI View Controller then I get EXC_BAD_ACCESS.. =/
Please find the code of my problematic View Controller below. I'm not very sure about it myself, because I used loadView to build its View. However apart from this interruption problem it works fine.
StoreViewController.h
#import <UIKit/UIKit.h>
#protocol StoreViewDelegate <NSObject>
#optional
- (void)DirectionsClicked:(double)lat:(double)lon;
#end
#interface StoreViewController : UIViewController
{
double latitude;
double longitude;
NSString *description;
NSString *imageURL;
short rating;
NSString *storeType;
NSString *offerType;
UIImageView *imageView;
UILabel *descriptionLabel;
id<StoreViewDelegate> storeViewDel;
}
#property (nonatomic) double latitude;
#property (nonatomic) double longitude;
#property (nonatomic) short rating;
#property (nonatomic,retain) NSString *description;
#property (nonatomic,retain) NSString *imageURL;
#property (nonatomic,retain) NSString *storeType;
#property (nonatomic,retain) NSString *offerType;
#property (assign) id<StoreViewDelegate> storeViewDel;
#end
StoreViewController.m
#import "StoreViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface StoreViewController()
-(CGSize) calcLabelSize:(NSString *)string withFont:(UIFont *)font maxSize:(CGSize)maxSize;
#end
#implementation StoreViewController
#synthesize storeViewDel, longitude, latitude, description, imageURL, rating, offerType, storeType;
- (void)mapsButtonClicked:(id)sender
{
}
- (void)loadView
{
UIView *storeView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
// Colours
UIColor *lightBlue = [[UIColor alloc] initWithRed:(189.0f / 255.0f)
green:(230.0f / 255.0f)
blue:(252.0f / 255.0f) alpha:1.0f];
UIColor *darkBlue = [[UIColor alloc] initWithRed:(28.0f/255.0f)
green:(157.0f/255.0f)
blue:(215.0f/255.0f)
alpha:1.0f];
// Layout
int width = self.navigationController.view.frame.size.width;
int height = self.navigationController.view.frame.size.height;
float firstRowHeight = 100.0f;
int margin = width / 20;
int imgWidth = (width - 3 * margin) / 2;
// Set ImageView
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(margin, margin, imgWidth, imgWidth)];
CALayer *imgLayer = [imageView layer];
[imgLayer setMasksToBounds:YES];
[imgLayer setCornerRadius:10.0f];
[imgLayer setBorderWidth:4.0f];
[imgLayer setBorderColor:[lightBlue CGColor]];
// Load default image
NSData *imageData = [NSData dataWithContentsOfFile:#"thumb-null.png"];
UIImage *image = [UIImage imageWithData:imageData];
[imageView setImage:image];
[storeView addSubview:imageView];
// Set Rating
UIImageView *ratingView = [[UIImageView alloc] initWithFrame:CGRectMake(3 * width / 4 - 59.0f,
margin,
118.0f,
36.0f)];
UIImage *ratingImage = [UIImage imageNamed:#"bb-rating-0.png"];
[ratingView setImage:ratingImage];
[ratingImage release];
[storeView addSubview:ratingView];
// Set Get Directions button
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(3 * width / 4 - 71.5f,
36.0f + 2*margin,
143.0f, 63.0f)];
[btn addTarget:self action:#selector(mapsButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
UIImage *mapsImgUp = [UIImage imageNamed:#"bb-maps-up.png"];
[btn setImage:mapsImgUp forState:UIControlStateNormal];
[mapsImgUp release];
UIImage *mapsImgDown = [UIImage imageNamed:#"bb-maps-down.png"];
[btn setImage:mapsImgDown forState:UIControlStateHighlighted];
[mapsImgDown release];
[storeView addSubview:btn];
[btn release];
// Set Description Text
UIScrollView *descriptionView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f,
imgWidth + 2 * margin,
width,
height - firstRowHeight)];
descriptionView.backgroundColor = lightBlue;
CGSize s = [self calcLabelSize:description withFont:[UIFont systemFontOfSize:18.0f] maxSize:CGSizeMake(width, 9999.0f)];
descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(margin, margin, width - 2 * margin, s.height)];
descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
descriptionLabel.numberOfLines = 0;
descriptionLabel.font = [UIFont systemFontOfSize:18.0f];
descriptionLabel.textColor = darkBlue;
descriptionLabel.text = description;
descriptionLabel.backgroundColor = lightBlue;
[descriptionView addSubview:descriptionLabel];
[storeView addSubview:descriptionView];
[descriptionLabel release];
[lightBlue release];
[darkBlue release];
self.view = storeView;
[storeView release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[imageView release];
[descriptionLabel release];
[super dealloc];
}
#end
Any suggestions ?
Thank you,
F.
Perhaps look at your crash report, get an idea of where it's crashing, and help us help you by posting the relevant code if it is not clear to you what is causing the crash. We may be able to help you further, but we need you to do some pre-requisite work first, like trying to solve it yourself with the appropriate information at hand. Now that you know what to look for, please, go forth and unicorn!
The problem was that I released some UIImages that were never allocated. Erasing the following lines solved my issue:
[ratingImage release];
[mapsImgUp release];
[mapsImgDown release];
F.
i ve created a uiscrollview containing a page control which loads the images from resource bundle..everything works good.i m able to scroll through different images..the problem is if i m to click the corresponding pagecontrol(dot), i m not able to navigate to the corresponding image....could u guys help me out below is the code...the below code works perfectly fine
// Email.h
#interface Email : UIViewController<UIScrollViewDelegate>
{
UIPageControl *pageControl;
UIScrollView *scroller;
}
#property (nonatomic,retain)IBOutlet UIPageControl *pageControl;
#property (nonatomic,retain)IBOutlet UIScrollView *scroller;
-(IBAction)clickPageControl:(id)sender;
#end
// Email.m
#implementation Email
#synthesize pageControl,scroller;
-(IBAction)clickPageControl:(id)sender
{
int page=pageControl.currentPage;
CGRect frame=scroller.frame;
frame.origin.x=frame.size.width=page;
frame.origin.y=0;
[scroller scrollRectToVisible:frame animated:YES];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int page = scrollView.contentOffset.x/scrollView.frame.size.width;
pageControl.currentPage=page;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title=#"Press Photos";
for (int i=1; i<10; i++)
{
UIImageView *images=[[UIImageView alloc]initWithImage:
[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",i]]];
images.frame=CGRectMake((i-1)*320, 0, 320, 460);
[scroller addSubview:images];
[images release];
}
scroller.delegate=self;
scroller.contentSize=CGSizeMake(320*9, 460);
scroller.pagingEnabled=YES;
pageControl.numberOfPages=9;
pageControl.currentPage=0;
}
frame.origin.x=frame.size.width=page;
should be
frame.origin.x = frame.size.width * page;