开发者

How do I implement UIScrollView programatically

开发者 https://www.devze.com 2023-01-25 01:58 出处:网络
I am launching detail pages from a UITableView and within that detail page there is an image. I would like it to be zoomable, so I\'d like the contents of that detail page to sit inside a scrollView.

I am launching detail pages from a UITableView and within that detail page there is an image. I would like it to be zoomable, so I'd like the contents of that detail page to sit inside a scrollView. So far no luck, the labels, textviews and images are fine, but I can't get the ScrollView implemented.

here is my .m: THANKS!

- (void)viewDidLoad {

 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
 scrollView.contentSize = CGSizeMake(320, 700);
 scrollView.clipsToBounds = YES;
 super.view.backgroundColor = [UIColor whiteColor];
 [scrollView setUserInteractionEnabled:YES];




 self.navigationItem.title = [NSString stringWithFormat:selectedCellItem];



 CGRect frame = CGRectMake(0, 0, 10, 10);

 self.view = [[UIView alloc] initWithFrame:frame];

 self.view.backgroundColor = [UIColor whiteColor];



 frame = CGRectMake(0, 320, 10, 10);



 UILabel *label = [[UILabel alloc] initWithFrame:frame];

 //label.text = selectedCellItem;


 label.font=[UIFont fontWithName:@"Verdana-Bold" size:20.0];
 label.textAlignment = UITextAlignmentCenter;

 [self.view addSubview:label];

 [label release];

 frame = CGRectMake(0, 320, 320, 60); //Description



 UITextView *labelDesc = [[UITextView alloc] initWithFrame:frame];

 labelDesc.text = selectedCellDesc;
 labelDesc.font=[UIFont fontWithName:@"Verdana" size:12.0];
 labelDesc.textAlignment = UITextAlignmentLeft;

 //labelDesc.textAlignment = UITextAlignmentTop;

 [self.view addSubview:labelDesc];

 [labelDesc release];




 frame = CGRectMake(0, 0, 320, 320); //Image

 UIImageView *imageItem = [[UIImageView alloc] initWithFrame:frame];
 [imageItem setImage:[UIImage imageNamed:selectedCellImage]];

 // GET THIS ONE WORKING RIGHT>>[imageItem setImage:[UIImage imageName开发者_运维问答d:[NSString stringWithFormat:@"%@.png", [[NSBundle mainBundle] bundlePath], selectedCellImage]]]; //use 

 //imageItem = [[UIImageView alloc] initWithContentsOfFile:[NSString stringWithFormat:@"shirt.png", [[NSBundle mainBundle] bundlePath]]];
 //labelDesc.font=[UIFont fontWithName:@"Zapfino" size:13.0];
 //labelDesc.textAlignment = UITextAlignmentCenter;

 imageItem.contentMode = UIViewContentModeScaleAspectFit;
 [self.view addSubview:imageItem];






 //[imageItem release];

    [super viewDidLoad];

}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (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 {
    [super dealloc];
}


@end


I think that you're missing the following line to add the UIScrollView as a subview.

[self.view addSubView:scrollView];

0

精彩评论

暂无评论...
验证码 换一张
取 消