Как создать вид изображения с помощью кнопки? - PullRequest
0 голосов
/ 25 июля 2011

enter image description here

Я хочу создать 32 вида, как показано выше. так, что я изменяю в своем коде, чтобы я получил это представление? Я показал код ниже

 - (void)loadView {
[super loadView];
self.view.backgroundColor = [UIColor redColor];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 33;
[btnMenu setTag:0 ];
for (int i = 1; i < numberOfViews; i++) {
    CGFloat yOrigin = i * self.view.frame.size.width;
    UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
            btnMenu = [UIButton buttonWithType:UIButtonTypeCustom];
    //NSData *data =UIImageJPEGRepresentation(, 1);
    [btnMenu setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"page-%d.jpg",i]] forState:UIControlStateNormal];
    CGRect frame = btnMenu.frame;
    frame.size.width=320;
    frame.size.height=420;
    frame.origin.x=0;
    frame.origin.y=0;
    btnMenu.frame=frame;
    [btnMenu setTag:i];
    btnMenu.alpha = 1;
    [btnMenu addTarget:self action:@selector(btnSelected:) forControlEvents:UIControlEventTouchUpInside];
    [awesomeView addSubview:btnMenu];

    [scroll addSubview:awesomeView];
    [awesomeView release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];
[scroll release];}

-(IBAction)btnSelected:(id)sender{
UIButton *button = (UIButton *)sender;
int whichButton = button.tag;
NSLog(@"Current TAG: %i", whichButton);
if(whichButton==1)
{
    first=[[FirstImage alloc]init];
    [self.navigationController pushViewController:first animated:YES];
        }
    }  

1 Ответ

0 голосов
/ 25 июля 2011
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

напишите эту строку в вашем коде перед циклом for.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...