Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button with different width on iPhone 5

I want to increase the size of a custom button if the user is using an iPhone 5.

This is what I have in my .m file

//.m File
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        int varWidth = 228;
    }
    if(result.height == 568)
    {
        int varWidth = 272;
    }
}

....

[newButton setFrame:CGRectMake(8.0, 40.0, 228, 80.0)];

But I want something like this:

[newButton setFrame:CGRectMake(8.0, 40.0, varWidth, 80.0)];
like image 226
Berendschot Avatar asked Jan 17 '26 18:01

Berendschot


1 Answers

You are using varWidth out of it's scope.

int varWidth;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        varWidth = 228;
    }
    if(result.height == 568)
    {
        varWidth = 272;
    }
}

....

[newButton setFrame:CGRectMake(8.0, 40.0, varWidth, 80.0)];
like image 181
Baby Groot Avatar answered Jan 20 '26 08:01

Baby Groot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!