开发者

How i create image view with button?

How i create image view with button?

I want create 32 views like above view. so that what i modify in my code so i get this view? I shown code below

 - (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.w开发者_如何学Pythonidth, 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];
        }
    }  


scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

write this line in your code before the for loop.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜