iOS Tips【持续更新】

作者: 0o冻僵的企鹅o0 | 来源:发表于2016-02-22 10:29 被阅读106次

1.DSYM在哪?
使用Finder前往路径

~/Library/Developer/Xcode/Archives/

2.UITextField的placeholder属性修改

textField.placeholder = @"xxxx";  
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

3.全局替换系统字体
如果你的app是纯代码写的,那么只要创建一个category就可以替换app内所有系统字体。
UIFont+SystemFontOverride.h

#import <UIKit/UIKit.h>

@interface UIFont (SystemFontOverride)
@end

UIFont+SystemFontOverride.m

@implementation UIFont (SystemFontOverride)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize {
    return [UIFont fontWithName:@"fontName" size:fontSize];
}

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize {
    return [UIFont fontWithName:@"fontName" size:fontSize];
}

#pragma clang diagnostic pop

@end

参考:

http://stackoverflow.com/a/17977354

4.获取ipa中所有图片资源

https://github.com/devcxm/iOS-Images-Extractor

5.代码片段(CodeSnippets)路径

~/Library/Developer/Xcode/UserData/CodeSnippets 

知道此路径就可以将代码片段使用git来管理,方便各个终端同步。


6.下面方法获取资源路径为nil

- (NSString *)pathForResource:(NSString *)name
                       ofType:(NSString *)extension

解决办法:target->Build Phases->Copy bundle resource,点击下面“+”,手动添加资源文件。


7.移除代码在git版本下的控制
cd 到工程目录,然后执行下面代码:

rm -rf .git

8.swift 学习资料
http://www.swiftguide.cn


9.文字尾部加入图片
http://www.jianshu.com/p/fcf6d9b88749


10.viewController 瘦身
http://www.jianshu.com/p/5316440fe78a


11.提取ipa中的图片素材
https://github.com/devcxm/iOS-Images-Extractor/blob/master/README_zh-Hans.md


12.修改stausbar文字颜色
全局控制,在plist文件中添加:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>

如果只改变单个页面,有两种情况:
在导航控制器下的UIViewController中:

self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

在非导航控制器下的UIViewController中:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

13.监听UITextField中字数的变化
方法1:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textFieldDidChange:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:_textField];

记得在dealloc方法中移除观察者。

方法2:

[textField addTarget:self 
              action:@selector(textFieldDidChange:) 
    forControlEvents:UIControlEventEditingChanged];

14.IT技能图谱
https://github.com/TeamStuQ/skill-map


15.改 UISearchBar 圆角的小技巧

摘自:改 UISearchBar 圆角的小技巧

首先在 UIView 的 category 里加一个方法:

UIView+Utils.m

- (UIView*)subViewOfClassName:(NSString*)className {
    for (UIView* subView in self.subviews) {
        if ([NSStringFromClass(subView.class) isEqualToString:className]) {
            return subView;
        }

        UIView* resultFound = [subView subViewOfClassName:className];
        if (resultFound) {
            return resultFound;
        }
    }
    return nil;
}

用的时候:

UIView* backgroundView = [searchBar subViewOfClassName:@"_UISearchBarSearchFieldBackgroundView"];
backgroundView.layer.cornerRadius = 14.0f;
backgroundView.clipsToBounds = YES;

用这个方法还可以改取消按钮的颜色、字体.


16.纬度和经度在 iOS 上最精确的类型是什么?

答:double/CLLocationDegrees。参考


17.去掉UITableView风格为group时候的最顶部的空白距离

CGRect frame=CGRectMake(0, 0, 0,CGFLOAT_MIN); 
self.tableView.tableHeaderView=[[UIView alloc]initWithFrame:frame];

18.解析苹果审核反馈崩溃日志 .crash 文件
解析苹果审核反馈崩溃日志 .crash 文件


19.Carthage 包管理工具
Carthage 包管理工具,另一种敏捷轻快的 iOS & MAC 开发体验
Carthage 的一点使用技巧


20.SDWebImage缓存策略吗
天天都在用的 SDWebImage, 你了解它的缓存策略吗?


21.iOS中NSLog输出格式大全

格式 意义
%@ 对象
%d, %i 整数
%u 无符整形
%f 浮点/双字
%x, %X 二进制整数
%o 八进制整数
%zu size_t
%p 指针
%e 浮点/双字 (科学计算)
%g 浮点/双字
%s C 字符串
%.*s Pascal字符串
%c 字符
%C unichar
%lld 64位长整数(long long)
%llu 无符64位长整数
%Lf 64位双字

22.字体最小值设定

textField.minimumFontSize = 12;
textField.adjustsFontSizeToFitWidth = YES;

23.通过appid 获取app的图标(icon)
参考:iPhone App: how to get app icon from app id?

NSString *idString = @"id389801252";

NSString *numericIDStr = [idString substringFromIndex:2]; // @"389801252"
NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", numericIDStr];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *json = [NSData dataWithContentsOfURL:url];

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];
NSArray *results = [dict objectForKey:@"results"];
NSDictionary *result = [results objectAtIndex:0];
NSString *imageUrlStr = [result objectForKey:@"artworkUrl100"]; // or 512, or 60

NSURL *artworkURL = [NSURL URLWithString:imageUrlStr];
NSData *imageData = [NSData dataWithContentsOfURL:artworkURL];
UIImage *artworkImage = [UIImage imageWithData:imageData];

24.__IPHONE_OS_VERSION_MAX_ALLOWED__IPHONE_OS_VERSION_MIN_REQUIRED

关于__IPHONE_OS_VERSION_MAX_ALLOWED__IPHONE_OS_VERSION_MIN_REQUIRED::

__IPHONE_OS_VERSION_MAX_ALLOWED系统最高版本(可以理解为当前设备的系统版本)

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
// 系统版本在iOS7.0及以上则编译此部分代码
#else
// 如果低于iOS7.0则编译此部分代码
#endif

__IPHONE_OS_VERSION_MIN_REQUIRED 系统最低版本(也就是iOS Deployment Target选择的版本)

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_0
// 如果选择(iOS Deployment Target)的最低支持版本在iOS7.0及以上才可以使用
- (void)execute;
#endif

__IPHONE_OS_VERSION_MAX_ALLOWED 这个宏得到的是设备当前的系统版本
__IPHONE_OS_VERSION_MIN_REQUIRED 这个宏它可以根据当前的选择的编译环境进行预编译处理


25.项目体积优化

http://www.jianshu.com/p/a72d03e92c80

http://www.zoomfeng.com/blog/ipa-size-thin.html

  1. AFN 返回json为空转为空字符串

AFJSONResponseSerializer *response = [AFJSONResponseSerializer serializer];
response.removesKeysWithNullValues = YES;

  1. cocoapods更新索引
pod repo update

如果不行,就先删除本地索引,再建索引,删除方法:

rm ~/Library/Caches/CocoaPods/search_index.json

再搜索就会重建索引了

  1. 配置文件地址
~/Library/MobileDevice/Provisioning Profiles

更新配置文件后,清理本地缓存,然后重新拉取

29.UISearchBar 在iOS 11变高
解决办法:

if ([[UIDevice currentDevice] systemVersion].doubleValue >= 11.0)
{
   [[searchbar.heightAnchor constraintEqualToConstant:44.0] setActive:YES];
}

30.查看一个静态库是否支持64位
步骤:
1).cd 到.a 文件所在的文件夹;
2).执行如下命令

lipo -info xxxx.a

结果:

Architectures in the fat file: xxxx.a are: armv7 i386 x86_64 arm64 

说明支持64位。

31.MLLabel 点击链接与所在viewA手势冲突解决:
在viewA的手势代理中添加如下代码:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return ![self.titleLb linkAtPoint:[touch locationInView:self.titleLb]];
}

相关文章

  • iOS Tips(持续更新)

    1、网络请求封装采用类方法还是单例模式?2、extern字符串常量,宏定义字符串常量怎么选?const常量有数据类...

  • iOS Tips【持续更新】

    1.DSYM在哪?使用Finder前往路径 2.UITextField的placeholder属性修改 3.全局替...

  • iOS开发Tips(持续更新)·····

    ·本文旨在总结iOS开发中一些小技巧,帮助更高效进行代码编写:1、 纯代码开发中便于展示一些控件所在空间位置来使用...

  • tips 持续更新

    在swift中的变量一般分为三种: swift - 类在数组中的写法 swift - 状态栏隐藏方法 xcode ...

  • android 常用小知识点 tips (二)

    android 常用小知识点 tips (一)android 常用小知识点 tips (二) 持续更新中.... ...

  • iOS 开发中的Tips

    iOS Tips 这里将记录iOS开发中的技巧,不定期更新内容 reloadData 调用 reloadData ...

  • CSS tips(持续更新...)

    处理文字溢出省略号代替: 使用box-shadow,制作四周阴影: 移动端viewport “三件套” : 让元素...

  • Swift Tips(持续更新)

    通过字符串创建类对象 在swift中打印对象时,会发现在类型前面总会有命名空间 +.+ 类名; 在swift中用字...

  • Swift Tips(持续更新)

    1、NSMutableAttributedString to String 2、swift中的交换元素使用swif...

  • Android Tips

    Android Tips将持续更新 Mac Mac系统下,打开Android SDK Manager Androi...

网友评论

    本文标题:iOS Tips【持续更新】

    本文链接:https://www.haomeiwen.com/subject/nlbdkttx.html