2011-08-01 51 views
0

在我的应用程序中,我有一个视图,在当前视图上方弹出以帮助用户(如果需要)。 问题是这样的:在iPhone 4上,该视图的关闭按钮看起来不错,而在iPhone 3GS上它有一个小凸起。我不知道为什么。同样的事情发生在复选框上。控制器在iPhone 4上看起来不错,但在iPhone 3GS上看起来不好,为什么?

以下是Picasa相册中的图片(有2张图片,一张名为iPhone 3GS,另一张iPhone 4,请参阅关闭按钮上方的凸块以及iPhone 3GS图片中的复选框)。

https://picasaweb.google.com/103964563927969565521/StackoverflowPosts?authkey=Gv1sRgCKWHu6mKj4OS5AE

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

// 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。

+0

您正在创建哪个iphone? – nicks

+0

你能告诉我们close_button.png的样子吗?如果你有一个[email protected]。 –

+0

我上传了上面相同链接的按钮图片,请看看。 –

回答

0

嗯,它看起来有点像RoundRect,默认绘图是从Jonathan所说的图形后面流出来的。而不是你的图形搞乱,我建议改变你的按钮类型,以UIButtonTypeCustom

closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

这将使一个按钮,通过您设置的图形和文本之外没有UI元素。

0

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

+0

你说得对。我有2个PNG文件。一个是用@ 2x的iPhone 4。这是否意味着iPhone 3GS图片太小或什么?你如何建议解决这个问题? –

+0

测量close_button.png文件并确保您的kCloseButtonWidth和kCloseButtonHeight完全匹配。 –

0
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 
相关问题