控件在 iPhone 4 上看起来不错,但在 iPhone 3GS 上看起来很糟糕,为什么?

发布于 2024-11-27 01:19:06 字数 1494 浏览 0 评论 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];

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

谢谢, 沙乌尔.

In my app, I have a view that pops above the current view to help the user if it's needed.
The problem is this: On iPhone 4, the close button of that view looks good while on iPhone 3GS it has a small bump above it. I have no idea why. Same thing happens with a checkbox.

Here are the pictures in the Picasa album (there are 2 pictures, one called iPhone 3GS and the other iPhone 4, see the bumps above the close button and the checkbox in the iPhone 3GS picture).

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

This is the code used to create the close button:

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

I don't know what to do, please help.

Thanks,
Shaul.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄居者 2024-12-04 01:19:06

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

closeButton = [UIButton buttonWithType:UIButtonTypeCustom];

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

Hmm, it looks a bit like the RoundRect default drawing is bleeding out from behind your graphic as Jon has said. Rather than messing with your graphics, I would recommend changing your button type to UIButtonTypeCustom:

closeButton = [UIButton buttonWithType:UIButtonTypeCustom];

This will make a button with NO ui elements outside of the graphic and text that you set.

千年*琉璃梦 2024-12-04 01:19:06

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

I'm speculating as I can't see your close_button.png files, but I think the problem is that your close_button.png and the button you are creating are different sizes, and the bump you are seeing is the default drawing of the round rect button.

猫瑾少女 2024-12-04 01:19:06
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文