控件在 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];
我不知道该怎么办,请帮忙。
谢谢, 沙乌尔.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,看起来有点像 RoundRect 默认绘图从图形后面渗出,正如乔恩所说。我建议您将按钮类型更改为 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:
This will make a button with NO ui elements outside of the graphic and text that you set.
我猜测是因为我看不到您的 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.