ios7 - How to set frame to UIBUTTON based on device type? -


i want set frame uibutton based on device 5,6,6plus,i tried below code getting trouble 6plus,for 6,6plus same method (is_iphone_6_6plus)is getting called,what,s wrong code please let me know.

#define is_iphone_6_6plus  ([[uiscreen mainscreen] bounds].size.height >= 667)?true:false #define is_iphone6plus  ([[uiscreen mainscreen] bounds].size.width >= 414)?true:false #define is_iphone_4  ([[uiscreen mainscreen] bounds].size.height == 480)?true:false #define is_iphone_5 ( fabs( ( double )[ [ uiscreen mainscreen ] bounds ].size.height - ( double )568 ) < dbl_epsilon )   - (void)viewdidload { if (is_iphone_5)      {         loginview.frame = cgrectmake(108, 393, 35, 35);         _signinbutton.frame=cgrectmake(173,393, 35,35);      }      else if (is_iphone_6_6plus)      {          loginview.frame = cgrectmake(128, 476, 35, 35);          _signinbutton.frame=cgrectmake(208,476, 35,35);       }      else if (is_iphone6plus)      {           loginview.frame = cgrectmake(118, 506, 35, 35);          _signinbutton.frame=cgrectmake(163,506, 35,35);       } } 

thanks in advance.

don't know how have define size of devices. think wrong defining size of different devices this:-

#define is_ipad (ui_user_interface_idiom() == uiuserinterfaceidiompad) #define is_iphone (ui_user_interface_idiom() == uiuserinterfaceidiomphone) #define is_retina ([[uiscreen mainscreen] scale] >= 2.0)  //--use main screen check screen height , width #define screen_width ([[uiscreen mainscreen] bounds].size.width) #define screen_height ([[uiscreen mainscreen] bounds].size.height) #define screen_max_length (max(screen_width, screen_height)) #define screen_min_length (min(screen_width, screen_height))  //--defining length according size of different devices #define is_iphone_4_or_less (is_iphone && screen_max_length < 568.0) #define is_iphone_5 (is_iphone && screen_max_length == 568.0) #define is_iphone_6 (is_iphone && screen_max_length == 667.0) #define is_iphone_6p (is_iphone && screen_max_length == 736.0) 

now can set button's (x,y,width,height) set in different devices.

like:-

    if(is_iphone_4_or_less)     {         //set button according iphone 4        //your button looks in iphone 4 or less     }     if(is_iphone_5)     {         //set button according iphone 5        //your button looks in iphone 5      }     if(is_iphone_6)     {         //set button according iphone 6        //your button looks in iphone 6     }     if(is_iphone_6p)     {         //set button according iphone 6 plus        //your button looks in iphone 6 plus     } 

note:-

it include size of iphone , ipad both. so, can use making constant file , import in view controller , use same above..


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -