0

在我的应用程序中,我有一个在当前视图上方弹出的视图,以便在需要时帮助用户。问题是:在 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];

我不知道该怎么办,请帮忙。

谢谢,肖尔。

4

3 回答 3

0

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

于 2011-08-01T07:54:36.270 回答
0

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

closeButton = [UIButton buttonWithType:UIButtonTypeCustom];

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

于 2011-08-01T21:25:25.447 回答
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
于 2011-08-01T21:34:59.537 回答