Search code examples
iosxcodeuibuttoniphone-5

UIButton not touchable - customizing from iPhone 4 to iPhone 5


I am working on my app to make compatible to iphone 5. In the following code, donebutton works for iphone 4, but when it comes to iphone5 it is not touchable! I dont know why?

 float screenSizeHeight=[UIScreen mainScreen].bounds.size.height;


if(screenSizeHeight==568)
{
    UIImageView *my_image_view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Plain_Background2.png"]];
    [my_image_view setFrame:CGRectMake(0,20,320,568)];
    [self.view addSubview:my_image_view];
    [self.view sendSubviewToBack:my_image_view];

    imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    [doneButtonOutlet setFrame:CGRectMake(124,470,72,28)];
}
if(screenSizeHeight==480)
{
    UIImageView *my_image_view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Plain_Background.png"]];
    [my_image_view setFrame:CGRectMake(0,20,320,480)];
    [self.view addSubview:my_image_view];
    [self.view sendSubviewToBack:my_image_view];
    imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 400)];
    [doneButtonOutlet setFrame:CGRectMake(124,432,72,28)];
}

Solution

  • This is because in iPhone 5 scrollView height is more and it is above your button.

    So change origin y of UIButton.

        imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)]; 
    // Here imageScrollView bottom is at 480 pixel and doneButtonOutlet origin is at 470 so either small height of scrollview or change button origin y.. 
            [doneButtonOutlet setFrame:CGRectMake(124,470,72,28)];
    

    Hope it helps you.