1. 相对路径
$(SRCROOT)/
2. 把返回按钮的文字隐藏
3. 改变 NavigationBar 的字体颜色
NavigationBar 上面有两处可以改变字体颜色,一是标题,二是左右按钮的文字。
改变按钮的文字颜色:
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
改变标题的文字颜色:
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
4. 去掉 NavigationBar 下方的阴影
iOS 7 NavigationBar的下方默认是有一条阴影的,如果想要 NavigationBar 和下面内容的背景颜色融为一体的话,就要去掉这个阴影:
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
改变 TabBar 的字体颜色
[UITabBarItem.appearance setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blueColor] } forState:UIControlStateNormal];[UITabBarItem.appearance setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] } forState:UIControlStateSelected];
5. 改变 StatusBar 的颜色
iOS7以后,status bar 的背景颜色变成了透明色,而且系统会根据 app的颜色自动改变 status bar 的字体颜色(黑和白)。但是这个自动改变的字体颜色并不一定和所有的 app 都搭配,比如我们 app 的主题色是稍微浅一丢丢的蓝,但是系统匹配的 status bar 的字体颜色就是黑色,看起来就很不爽,所以就要强制将其改为白色。
首先在 Info.plist 中的 Information Property List
中添加一个 Key为Viewcontroller-based status bar appearance
的 item,其 Type 设为 Boolean,Value 设为 NO
然后在AppDelegate.m的application:didFinishLaunchingWithOptions:
中添加:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
6. 隐藏 StatusBar
有时候为了实现沉浸式设计,比如 app 首次打开的引导页,需要隐藏整个 StatusBar,方法如下:
和改变 StatusBar 颜色一样,在 Info.plist 中的 Information Property List
中添加一个 Key为View controller-based status bar appearance
的 item,其 Type 设为 Boolean,Value 设为 NO
在需要隐藏StatusBar 的 ViewController 中的viewDidLoad加入以下代码:
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self setNeedsStatusBarAppearanceUpdate];
}
重写prefersStatusBarHidden:
-(BOOL)prefersStatusBarHidden {
return YES;
}
注:但是这样设置的话从这个页面开始整个 app 的 StatusBar 都会隐藏,如果想要再显示出来,只需要在其他 ViewController 中加入:
[UIApplication sharedApplication].statusBarHidden = NO;
7. 用Reveal连接模拟器调试
首先打开Terminal
,输入 vim ~/.lldbinit
创建一个名为.lldbinit
的文件,然后将如下内容输入到该文件中:
command alias reveal_load_sim expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2);
command alias reveal_load_dev expr (void*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0x4], 0x2);
command alias reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
command alias reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];
该步骤其实是为lldb设置了4个别名,为了后续方便操作,这4个别名意义如下:
reveal_load_sim
为模拟器加载reveal调试用的动态链接库
reveal_load_dev
为真机加载reveal调试用的动态链接库
reveal_start
启动reveal调试功能
reveal_stop
结束reveal调试功能
接下来,我们在AppDelegate类的 application: didFinishLaunchingWithOptions:
点击该方法左边的行号区域,增加一个断点,之后右击该断点,选择“Edit Breakpoint”。
点击”Action”项边右的”Add Action”,然后输入“reveal_load_sim
”
勾选上Options上的”Automatically continue after evaluating
”选项。
之后我们运行模拟器,然后打开Reveal,就可以在Reveal界面的左上角,看到有模拟器可以连接调试,选择它,则可以在Reveal中查看和调试该iOS程序的界面了。