开发者

Controls look good on iPhone 4 but look bad on iPhone 3GS, why?

开发者 https://www.devze.com 2023-03-24 00:33 出处:网络
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 smal

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]开发者_如何学JAVA 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.


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消