Uiview 为什么iPhone4上的控件看起来不错,但iPhone3GS上的控件看起来不好?

Uiview 为什么iPhone4上的控件看起来不错,但iPhone3GS上的控件看起来不好?,uiview,ios4,uibutton,uiwindow,Uiview,Ios4,Uibutton,Uiwindow,在我的应用程序中,我有一个在当前视图上方弹出的视图,可以在需要时帮助用户。 问题在于:在iPhone4上,该视图的关闭按钮看起来不错,而在iPhone3GS上,它的上方有一个小突起。我不知道为什么。复选框也会发生同样的情况 这是Picasa相册中的图片。有两张图片,一张叫做iPhone3GS,另一张叫做iPhone4。请参见“关闭”按钮上方的凸起和iPhone3GS图片中的复选框 这是用于创建关闭按钮的代码: // Close button closeButton = [UIButton

在我的应用程序中,我有一个在当前视图上方弹出的视图,可以在需要时帮助用户。 问题在于:在iPhone4上,该视图的关闭按钮看起来不错,而在iPhone3GS上,它的上方有一个小突起。我不知道为什么。复选框也会发生同样的情况

这是Picasa相册中的图片。有两张图片,一张叫做iPhone3GS,另一张叫做iPhone4。请参见“关闭”按钮上方的凸起和iPhone3GS图片中的复选框

这是用于创建关闭按钮的代码:

// Close button
    closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    float xCor = self.frame.size.width - kViewMargins - kCloseButtonWidth;
    float yCor = y + ((self.frame.size.height - y) / 2 - kCloseButtonHeight / 2);

    closeButton.frame = CGRectMake(xCor,
                                   yCor,
                                   kCloseButtonWidth,
                                   kCloseButtonHeight);  

    [closeButton setTitle:kClose forState:UIControlStateNormal];
    [closeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [[closeButton titleLabel] setFont:[UIFont boldSystemFontOfSize:kQuickTipTitleFontSize]];
    [closeButton setBackgroundImage:[UIImage imageNamed:@"close_button.png"] forState:UIControlStateNormal]; 
    [closeButton addTarget:self action: @selector (doneButtonClick)  forControlEvents: UIControlEventTouchUpInside]; 
    [self addSubview:closeButton];
我不知道该怎么办,请帮忙

谢谢,
Shaul。

我在猜测,因为我看不到你的close_button.png文件,但我认为问题在于你的close_button.png和你正在创建的按钮大小不同,你看到的凹凸是圆形矩形按钮的默认图形。

嗯,正如Jon所说,看起来有点像RoundRect默认图形从图形后面流出。我建议您将按钮类型更改为UIButtonTypeCustom,而不是干扰图形:


这将使一个按钮在您设置的图形和文本之外没有ui元素。

您是为哪个iphone创建的?能否向我们展示close_button.png的外观?最后呢_button@2x.png如果你有一个。我上传了按钮的图片,上面的链接相同,请看一看。你是对的。我有2个png文件。一个是用于带有@2x的iPhone4。这是不是意味着iPhone3GS的图片太小了?您建议如何解决该问题?测量close_button.png文件并确保您的kCloseButtonWidth和kCloseButtonHeight完全匹配。
closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage* closeImage = [UIImage imageNamed:@"close_button.png"];
float xCor = self.frame.size.width - kViewMargins - kCloseButtonWidth;
float yCor = y + ((self.frame.size.height - y) / 2 - kCloseButtonHeight / 2);

closeButton.frame = CGRectMake(xCor,
                               yCor,
                               closeImage.size.width/2,
                               closeImage.Size.height/2);  

[closeButton setTitle:kClose forState:UIControlStateNormal];
[closeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[[closeButton titleLabel] setFont:[UIFont boldSystemFontOfSize:kQuickTipTitleFontSize]];
[closeButton setBackgroundImage:closeImage  forState:UIControlStateNormal]; 
[closeButton addTarget:self action: @selector (doneButtonClick)  forControlEvents: UIControlEventTouchUpInside]; 
[self addSubview:closeButton];
[closeButton release]; /// you must release the closeButton
closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage* closeImage = [UIImage imageNamed:@"close_button.png"];
float xCor = self.frame.size.width - kViewMargins - kCloseButtonWidth;
float yCor = y + ((self.frame.size.height - y) / 2 - kCloseButtonHeight / 2);

closeButton.frame = CGRectMake(xCor,
                               yCor,
                               closeImage.size.width/2,
                               closeImage.Size.height/2);  

[closeButton setTitle:kClose forState:UIControlStateNormal];
[closeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[[closeButton titleLabel] setFont:[UIFont boldSystemFontOfSize:kQuickTipTitleFontSize]];
[closeButton setBackgroundImage:closeImage  forState:UIControlStateNormal]; 
[closeButton addTarget:self action: @selector (doneButtonClick)  forControlEvents: UIControlEventTouchUpInside]; 
[self addSubview:closeButton];
[closeButton release]; /// you must release the closeButton