tes*_*ing 8 iphone cocoa-touch objective-c uinavigationbar uitoolbar
我正在跟随这里的第二个提示.在这篇技巧文章中,两个UIBarButtonItems放在UIToolbar中.最后,UIToolbar被添加到UINavigationBar中.现在我的问题:
1)UIToolbar顶部有一条白线.如果我增加UIToolbar的大小,则渐变是错误的.我在UIToolbar上使用以下大小:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)];
Run Code Online (Sandbox Code Playgroud)
我该怎样摆脱白线?看这里:

问题是存在白色而不是灰色线.如果它是灰色的,一切都会很完美.
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];
Run Code Online (Sandbox Code Playgroud)
@ 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
Run Code Online (Sandbox Code Playgroud)
无法保证UIToolbar在UINavigationBar中无缝绘制; 这可能是你所看到的白线的原因.
您可能能够将UIToolbar子类化,以便它不会绘制(即覆盖-drawRect:不执行任何操作).
| 归档时间: |
|
| 查看次数: |
13310 次 |
| 最近记录: |