gpt4 book ai didi

iphone - 将带有两个 UIBarButtonItem 的 UIToolbar 添加到 UINavigationBar : poor UIToolbar and what about iPhone 4

转载 作者:太空狗 更新时间:2023-10-30 03:33:16 29 4
gpt4 key购买 nike

我正在关注来自 here 的第二条提示.在本技巧中,两个 UIBarButtonItem 被放在一个 UIToolbar 中。最后,将 UIToolbar 添加到 UINavigationBar。现在解决我的问题:

1) UIToolbar 顶部有一条白线。如果我增加 UIToolbar 的大小,渐变是错误的。我为 UIToolbar 使用以下尺寸:

    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)];

如何去除白线?看这里: alt text

问题是有一条白色线而不是灰色线。如果它是灰色的,一切都会很完美。

2) iPhone 3 和 iPhone 4 的显示尺寸有何不同?我是否必须检查使用的是哪部 iPhone,然后将尺寸加倍?

编辑:

按钮的创建方式与我从上述网站获取的以下示例类似:

// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];

// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];

// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];

// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];

// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];

[buttons release];

// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];

@tc.:

我试图子类化 UIToolbar

// MyToolbar.h

#import <Foundation/Foundation.h>


@interface MyToolbar : UIToolbar {

}

@end

// MyToolbar.m

#import "MyToolbar.h"


@implementation MyToolbar

- (void)drawRect:(CGRect)rect {
// do nothing
}

- (id)initWithFrame:(CGRect)aRect {
if ((self = [super initWithFrame:aRect])) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.clearsContextBeforeDrawing = YES;
}
return self;
}

@end

最佳答案

无法保证 UIToolbar 在 UINavigationBar 内无缝绘制;这可能是您看到的白线的原因。

您可以继承 UIToolbar 使其不绘制(即重写 -drawRect: 不做任何事情)。

关于iphone - 将带有两个 UIBarButtonItem 的 UIToolbar 添加到 UINavigationBar : poor UIToolbar and what about iPhone 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3789283/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com