2013-08-12 2 views
0

вот что я делаю в данный момент.Бесконечный горизонтальный UIScrollView с UIButtons

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(56, 205, 400, 3000)]; 
scrollView.delegate = self; 
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3.0f,scrollView.frame.size.height * 3.0f); 
scrollView.maximumZoomScale = 3.0f; 

UIView *zoomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, scrollView.contentSize.width, scrollView.contentSize.height)]; 
zoomView.backgroundColor = [UIColor whiteColor]; 
for (NSInteger index = 0; index < 100; index++) 
{ 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    button.frame = CGRectMake((scrollView.frame.size.width/2.0f) - 50.0f, 10.0f + (50.0f * (CGFloat)index), 100.0f, 30.0f); 
    button.tag = index; 
    [button setTitle:[NSString stringWithFormat:@"Button %ld", ((long)index + 1)] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; 

    [zoomView addSubview:button]; 
} 

[scrollView addSubview:zoomView]; 
[self.view addSubview:scrollView]; 

Проблема есть. Это не так. Я бы хотел, чтобы номер 101 был номером 1, надеюсь, вы понимаете. И как я могу создать их динамически, с веб-сервисом, рассказывающим мне, сколько у меня кнопки, какой фон я должен применять к каждой кнопке, и какой текст поставить под кнопкой. Также приведенный выше код прокручивается по вертикали, но в конце это будет не масштабируемое горизонтальное прокрутка. Заранее спасибо.

+0

Вы хотите прокрутить свой UIScrollview до размера кадра zoomView? – chandan

ответ

0

Просто установите размер содержимого вашего Scrollview

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(56, 205, 400, 320)]; // it is for iphone. set it's resolution if you want to set it for ipad 
scrollView.delegate = self; 
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3.0f,scrollView.frame.size.height * 3.0f); 
scrollView.maximumZoomScale = 3.0f; 

UIView *zoomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, scrollView.contentSize.width, scrollView.contentSize.height)]; 
zoomView.backgroundColor = [UIColor whiteColor]; 
for (NSInteger index = 0; index < 100; index++) 
{ 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    button.frame = CGRectMake((scrollView.frame.size.width/2.0f) - 50.0f, 10.0f + (50.0f * (CGFloat)index), 100.0f, 30.0f); 
    button.tag = index; 
    [button setTitle:[NSString stringWithFormat:@"Button %ld", ((long)index + 1)] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; 

    [zoomView addSubview:button]; 
} 

[scrollView addSubview:zoomView]; 
[self.view addSubview:scrollView]; 

scrollView.contentSize= CGSizeMake((zoomView.frame.size.width) , zoomView.frame.size.height); 

установить его после того, как ваш вид масштабирования был добавлен в Scrollview. Надеюсь, это поможет вам понять.

Смежные вопросы