1

我有一个用于以编程方式创建按钮的代码,这里是

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]; 

所以现在我已经为按钮设置了框架,但是如果在 iPhone4 上以 640x960 看到这个应用程序怎么办?然后我有不同的图像“locBar@2x.png 和 locBarColor@2x.png”,它们应该使用不同的 CGRectMake,还是应该使用它们?我的问题是如何为两种分辨率设置一个按钮,并以编程方式进行。

4

3 回答 3

2

它是自动的 :) ios 将加载 @2x 版本(如果可用并且设备具有 x2 比例)​​。帧以点为单位,而不是以像素为单位。

这里 的点与像素

于 2012-02-09T12:56:53.533 回答
1

如果你包含一个高分辨率版本的同名图片,但在扩展名前加上@2x,iOS会根据显示分辨率自动选择正确的分辨率,只要你使用[UIImage imageNamed:]函数,或者在 IB 中设置图像。

于 2012-02-09T13:01:18.427 回答
-1

您必须设置条件,然后根据屏幕尺寸制作按钮框架并给它们图像。

于 2012-02-09T13:00:47.357 回答