iOS 需要使用却不常用的知识点

一、 iPhone Size

iOS 需要使用却不常用的知识点_第1张图片
屏幕快照 2016-07-01 上午9.47.24.png

二、 给navigation Bar 设置 title 颜色

UIColor *yellowColor = [UIColor yellowColor];
NSDictionary *colourDic = [NSDictionary dictionaryWithObject:yellowColor forKey:NSForegroundColorAttributeName];
[self.navigationController.navigationBar setTitleTextAttributes:colourDic];

三、 UIColor 获取 RGB 值

UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
const CGFloat *components = CGColorGetComponents(color.CGColor);
    NSLog(@"Red: %f", components[0]);
    NSLog(@"Green: %f", components[1]);
    NSLog(@"Blue: %f", components[2]);
    NSLog(@"Alpha: %f", components[3]);

四、 修改textField的placeholder的字体颜色、大小

self.textField.placeholder = @"CVHJBHDFBHDBGKDFBKH";
[self.textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[self.textField setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];

五、 线程中更新 UILabel的text

[self.label1 performSelectorOnMainThread:@selector(setText:)withObject:textDisplay
waitUntilDone:YES];

六、使用UIScrollViewKeyboardDismissMode实现了视图在滚动的时候回收键盘
这个属性使用了新的UIScrollViewKeyboardDismissMode enum枚举类型。这个enum枚举类型可能的值如下:

typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode) {
UIScrollViewKeyboardDismissModeNone,
UIScrollViewKeyboardDismissModeOnDrag,      // dismisses the keyboard when a drag begins
UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss
} NS_ENUM_AVAILABLE_IOS(7_0);

七、ios7 顶部时间statusbar 文字颜色
iOS7上,默认status bar字体颜色是黑色的,要修改为白色的需要在infoPlist里设置View controller-based status bar appearanceNO然后在AppDelegate中添加如下代码

application.statusBarStyle = UIStatusBarStyleLightContent;

八、获得当前硬盘空间

NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *fattributes = [fm attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
NSLog(@"容量%lldG",[[fattributes objectForKey:NSFileSystemSize] longLongValue]/1000000000);
NSLog(@"可用%lldG",[[fattributes objectForKey:NSFileSystemFreeSize] longLongValue]/1000000000);

九、iOS加载启动图的时候隐藏statusbar
只需要在info.plist中加入Status bar is initially hidden 设置为YES就好

十、iOS7 中 boundingRectWithSize:options:attributes:context:计算文本尺寸的使用

NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:13]};
CGSize size = [@"相关NSString" boundingRectWithSize:CGSizeMake(100, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

十一、iOS 开发,工程中混合使用 ARC 和非ARC
Xcode 项目中我们可以使用 ARC 和非 ARC 的混合模式。

如果你的项目使用的非 ARC 模式,则为 ARC 模式的代码文件加入 -fobjc-arc 标签。如果你的项目使用的是 ARC 模式,则为非 ARC 模式的代码文件加入 -fno-objc-arc 标签。添加标签的方法:

  • 打开:你的target -> Build Phases -> Compile Sources.
  • 双击对应的 *.m 文件
  • 在弹出窗口中输入上面提到的标签 -fobjc-arc / -fno-objc-arc
  • 点击 done 保存

十二、在UIViewController中property的一个UIViewController的Present问题

如果在一个UIViewController A中有一个property属性为UIViewController B,实例化后,将BVC.view 添加到主UIViewController A.view上,如果在viewB上进行** - (void)presentViewController:(UIViewController )viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);的操作将会出现,“ Presenting view controllers on detached view controllers is discouraged ”* 的问题。
以为BVC已经present到AVC中了,所以再一次进行会出现错误。可以使用以下代码解决:

[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:^{
NSLog(@"Finished");
}];

十三、改变TabBarItem上所有文字的颜色
正常时候的颜色

[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];

被选中时候的颜色

[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];

十四、改变tabBar的背景颜色

tab.tabBar.barTintColor = [UIColor blackColor];

十五、设置tabBar上所有导航栏的颜色

[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];

十六、设置label,或者button 这类控件的边框

self.label.layer.borderColor = [[UIColor orangeColor] CGColor];
self.label.layer.borderWidth = 5;
self.label.layer.masksToBounds = YES;

你可能感兴趣的:(iOS 需要使用却不常用的知识点)