網頁

2012年4月11日 星期三

iphone UIScrollView



How To Use UIScrollView in Your iPhone App


.h
@interface ViewController : UIViewController
{
    //IBOutlet UIImageView* teamContentView;
    IBOutlet UIImageView *imageView;
    
    IBOutlet UIScrollView* scrolContent;
}
@property (nonatomic, retain)UIScrollView *scrolContent; 
@end

.m
@implementation ViewController

@synthesize scrolContent;

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *image = [UIImage imageNamed: @"content.png"];
    UIImageView *imageViewScroll = [[UIImageView alloc] initWithImage:image];
   
    
    [scrolContent addSubview:imageViewScroll];
    [scrolContent setScrollEnabled:YES];
    [scrolContent setContentSize:CGSizeMake(250, 700)];   
}


注意 UICrollView不需超過螢幕大小 靠的是ContentSize 另一種純靠程式方法
.h
@interface ViewController : UIViewController
{
 UIView *headerView;
}

@property (nonatomic, retain) UIView *headerView;


- (void) initHeaderView;

@end
.m
@synthesize headerView;


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self initHeaderView];
    [self.view addSubview:headerView];


}
- (void) initHeaderView
{
 UIView *header = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 350)];
 
 UIScrollView *scroll = [[UIScrollView alloc] initWithFrame: CGRectMake(43, 22, 250, 328)];
 scroll.contentSize = CGSizeMake(250, 700);
 
 UIImage *image = [UIImage imageNamed: @"about_content.png"];
 UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
 imageView.userInteractionEnabled = YES;

 
 [scroll addSubview: imageView];
    
    //[self.view addSubview: scroll]; //without UIView header
 
    [header addSubview: scroll];

    
 self.headerView = header;


}

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。