前者在主视图中:
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
后者在子视图中:
self.navigationItem.hidesBackButton = YES;//隐藏返回按钮
哥怒了,这blog可视化编辑器插入代码老是显示html元素,搞了半个多小时,无力地抛弃之...
1.背景色:
(http://stackoverflow.com/questions/2259929/iphone-navigationbar-custom-background)网上说用category给UINavigationBar重写drawRect:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
可以用,他自己也说其实不是很好,我觉得不是很灵活
忘了在哪看到了,说是tintColor,经过测试确实如此,setBackgroundColor不行,tintColor就可以:
UINavigationBar *bar = self.navigationController.navigationBar;
bar.tintColor=[UIColor redColor];
而且连left/right button一起改了(前提是item用tittle初始化):
UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithTitle:@"ad1.png" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.rightBarButtonItem=item;
效果:
注意:用Image初始化的item加上去有点问题,会覆盖大部分bar,不解:
UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ad1.png"] style:UIBarButtonItemStyleBordered target:nil action:nil];
item.width=50;
self.navigationItem.rightBarButtonItem=item;
效果:
另,item用customview初始化的话,如用button,需要设置frame,不然不显示:
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(0, 0, 50, 30);
[btn setBackgroundImage:[UIImage imageNamed:@"ad1.png"] forState:UIControlStateNormal];
UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem=item;
效果:
2.不止改背景颜色的话,就得用imageView,貌似以前看过,反正就是insert到bar的subviews的0,要不add之后exchange一下,bar原先只有一个subview:
UIImageView *imageView=[[UIImageView alloc] initWithFrame:bar.bounds];
imageView.image=[UIImage imageNamed:@"adBg.png"];
[bar insertSubview:imageView atIndex:0];
[imageView release];
效果:
注意:只add的话会把tittle覆盖掉,故需exchange:
[bar addSubview:imageView];
[bar exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
再来一篇,获取本地IP,三种方法:
(1)在Day 4教程里面的NSHost(http://appsamuck.com/day4.html)也能取到IP,不过是私有的API
(2)从C struct的地址取(http://stackoverflow.com/questions/3538365/iphone-get-ip-address-of-the-current-wifi),有人回复说返回error,经过单步debug之后,发现只要修改一下即可,循环判断里面原来判断是"en0",单步的时候会得到en1值,加个或运算,即可正确返回,不知道还有木有en2,en3之类的…
(3)也是C的方式,不过更复杂(http://www.iphonedevsdk.com/forum/iphone-sdk-development/5293-get-current-ip-address.html 用了整个C文件…),说是从Mac下移植的,开始不用改就能用,后来又有帖子说,只能取一次,第二次调用返回null(http://www.iphonedevsdk.com/forum/iphone-sdk-development/26780-how-get-local-ip.html),又得单步debug…太复杂了,懒得debug,观察init和free之类的有木有问题,可能是没清空缓存之类的,发现有个static int的很可疑,既然每次都会保存上次的值,估计对本次会有影响,那么就应该在init里面重新初始化为0,至此OK
总的来说,光是靠拿来主义是不够滴,有些还是得自己动手,丰衣足食.细节是魔鬼
PS:由于引用的地址较多,再次一并谢过,包括楼主和各位回帖者(嘿嘿,估计老外朋友很难看到)