Search code examples
iphoneuibuttoncgrectmake

setFrame - I need some clarification for this


I have a code for programmatic creation of buttons, and here it is

UIImage *aroundImage = [UIImage imageNamed:@"locBar.png"];
    UIImage *aroundImageDown = [UIImage imageNamed:@"locBarColor.png"];
    UIButton *aroundButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aroundButton setFrame:CGRectMake(240, 369, 80, 48)];  
    [aroundButton setImage:aroundImage forState:UIControlStateNormal];
    [aroundButton setImage:aroundImageDown forState:UIControlStateHighlighted];
    [aroundButton setImage:aroundImageDown forState:UIControlStateSelected];
    [aroundButton addTarget:self action:@selector(aroundMe) forControlEvents:UIControlEventTouchUpInside];    
    [self.view addSubview:aroundButton]; 

so now i have set the frame for the button, but what if this app is seen on iPhone4 in 640x960. Then i have different images "locBar@2x.png and locBarColor@2x.png" and they should be with a different CGRectMake, or should they? My question is how do I set up a button for both resolutions, and do that programmatically .


Solution

  • it's automatic :) ios will load the @2x version if available and if the device has a x2 scale. The frame is in point, not in pixel.

    Look here in Points Versus Pixels