iOS开发杂记

下面的内容基本都是我亲测的

  • Xcode目录位置:~/Library/Developer/Xcode/
  • Code Snippets目录:~/Library/Developer/Xcode/UserData/CodeSnippets
  • 插件安装位置:~/Library/Application Support/Developer/Shared/Xcode/Plug-ins
  • profile:~/Library/MobileDevice/Provisioning Profiles
  • 在 iOS 7 中,如果某个 UIViewController 的 self.view 第一个子视图是 UIScollView, 同时当这个 UIViewController 被 push 或 initWithRootController 成为 UINavigationController控制的Controller时,这个 UIViewController的 view 的子视图 UIScollView 的所有子视图, 都会被下移 64px。http://unremittingly.iteye.com/blog/2031626
  • ios中json解析出现的null问题
  • 下载sinippet editor:http://cocoaholic.com/snippet_edit/
  • Xcode通配符:
    • Bundle name: $(PRODUCT_NAME)
    • Bundle identifier: $(PRODUCT_BUNDLE_IDENTIFIER)
  • Git同步远程被删除的分支:git remote prune origin
  • debugLog宏定义:
#ifdef DEBUG
    #define DebugLog(format, ...) NSLog((@"%s [Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
    #define DebugLog(...)
#endif
  • UITextView光标下移的问题:
UIViewController.automaticallyAdjustsScrollViewInsets = NO;
  • UINavigationBar设置返回按钮图片
self.navigationController.navigationBar.backIndicatorImage = self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [[UIImage imageNamed:@"navi_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  • 设置naviagationBar的title字体
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithHexString:@"#333333"], NSFontAttributeName: [UIFont systemFontOfSize:16.5]}];
  • separator 顶头
-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
        
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}
  • 自定义UITabBar高度:
  // 在UITabBarController的子类中调用
  - (void)viewWillLayoutSubviews
  {
    CGRect tabFrame = self.tabBar.frame; //self.TabBar is IBOutlet of your TabBar
    tabFrame.size.height = kTabbarH;
    tabFrame.origin.y = self.view.frame.size.height - kTabbarH;
    self.tabBar.frame = tabFrame;
  }
  • 改变UITabBar的文字颜色
  - (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes   forState:(UIControlState)state NS_AVAILABLE_IOS(5_0)   UI_APPEARANCE_SELECTOR;
  • 给UITabBarItem添加背景色
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageWithColor:UIColorFromHex(FFDC02) size:CGSizeMake(kScreenWidth / self.viewControllers.count, kTabbarH)]];
  • 改变UITabBarItem中文字的位置
[UITabBarItem appearance].titlePositionAdjustment = UIOffsetMake(0, -3);
  • UITableView separatorInset
  -(void)viewDidLayoutSubviews
  {
      if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
      {
          [self.tableView setSeparatorInset:UIEdgeInsetsZero];   
      }
      if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
      {
          [self.tableView setLayoutMargins:UIEdgeInsetsZero];
      }
  }
  - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell       forRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if ([cell respondsToSelector:@selector(setSeparatorInset:)])
      {
          [cell setSeparatorInset:UIEdgeInsetsZero];
      }
      if ([cell respondsToSelector:@selector(setLayoutMargins:)])
      {
          [cell setLayoutMargins:UIEdgeInsetsZero];
      }
  }
  • 自定义SearchBar的CancelButton
NSArray *searchBarSubViews = [[sc.searchBar.subviews objectAtIndex:0] subviews];
    for (UIView *searchbuttons in searchBarSubViews)
    {
        if ([searchbuttons isKindOfClass:[UIButton class]])
        {
            UIButton *cancelButton = (UIButton *) searchbuttons;
            cancelButton.enabled = YES;
            cancelButton.hidden = YES;
            [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; //文字
            [cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
            break;
        }
    }
  • 改变barItem图片的位置
UIBarItem.imageInsets
  • CAAnimation结束后保持最后位置
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
  • 复制一个view
  - (MyView *)duplicate
  {
    NSData * tempArchive = [NSKeyedArchiver archivedDataWithRootObject:self];
    return [NSKeyedUnarchiver unarchiveObjectWithData:tempArchive];
  }
  • 把view生成一个image
  - (UIImage *)imageWithView:(UIView *)view
  {
      UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen   mainScreen].scale);
      [view.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return image;
}
其中[UIScreen mainScreen].scale参数可以使生成的图片更清晰。
  • UIToolBar clearColor
  [toolBar setBackgroundImage:[UIImage alloc] forToolbarPosition:UIBarPositionAny   barMetrics:UIBarMetricsDefault];
  [toolBar setShadowImage:[UIImage alloc] forToolbarPosition:UIBarPositionAny];
  • 约束的符号断点 UIViewAlertForUnsatisfiableConstraints

  • Cocoa Touch template can be found from:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source.

  • 定制工程模板和类模板:http://www.jianshu.com/p/738d5697e869

  • NSURL的一些概念:

  NSURL *myUrl = [NSURL URLWithString:@"search?q=uiviewcontroller"
                          relativeToURL:[NSURL URLWithString:@"https://www.baidu.com/"]];
    
  NSLog(@"baseURL = %@", myUrl.baseURL);  //  https://www.baidu.com/
  NSLog(@"path = %@", myUrl.path);        //  /search
  NSLog(@"scheme = %@", myUrl.scheme);    //  https
  NSLog(@"resourceSpecifier = %@", myUrl.resourceSpecifier);  //  search?  q=uiviewcontroller
  NSLog(@"relativePath = %@", myUrl.relativePath);    //  search
  NSLog(@"relativeString = %@", myUrl.relativeString);    //  search?  q=uiviewcontroller
NSLog(@"absoluteURL = %@", myUrl.absoluteURL);  //    https://www.baidu.com/search?q=uiviewcontroller
  NSLog(@"absoluteString = %@", myUrl.absoluteString);    //      https://www.baidu.com/search?q=uiviewcontroller
  • 分类添加属性:http://www.jianshu.com/p/3cbab68fb856
  • 解决duplicate symbol OBJC_IVAR$ in:的方法:1. 查看项目结构里是不是有多个重复的文件 2.Build Phases -> Compile Sources里面是不是链接了多个.m
  • 创建单例的写法:
  /**
   *  初始化方法
   */
  + (instancetype)sharedManager
  {
      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
          _sharedManger = [[super allocWithZone:NULL] init];
      });
      return _sharedManger;
  }
  - (id)copyWithZone:(NSZone *)zone
  {
      return [YZJIMManager sharedManager];
  }

  + (id)allocWithZone:(struct _NSZone *)zone
  {
      return [YZJIMManager sharedManager];
  }
  • 解决navigationBar下面的子视图不能从navationBar开始计算frame的问题:
    self.edgesForExtendedLayout = UIRectEdgeNone;
  • iPhone 尺寸
机型 像素
6 p / 6s p 1242 * 2208 414 * 736
6 / 6s 750 * 1334 375 * 667
5 / 5c / 5s 640 * 1136 320 * 568
4 / 4s 640 * 960 320 * 480
  • 动态库提交app store
    为了能够顺利提交app至app store, 需要移除动态库中的x86_64和i386平台,具体操作如下:
  1. 进入libksygpulivedylib.framework目录,执行命令:
  2. lipo libksygpulivedylib -remove x86_64 -output libksygpulivedylib
  3. lipo libksygpulivedylib -remove i386 -output libksygpulivedylib
  4. 执行完成后可使用lipo -info libksygpulivedylib 命令确认当前的动态库已经移除上面两个平台。
  5. 如果不执行上述操作,那么在提交app store的时候,可能会出现ITMS-90087, ITMS-90209, ITMS-90125错误。
  • 上架需要的资源
screen shot : 上架尺寸
iPhone4 : 640x960 或者 960x640
iPhone5 640 x 1136或者1136 x 640
iPhone6 750 x 1334 或者1334 x 750
iPhone6 plus 1242 x 2208 或者 2208x1242 (phone 6 plus实际分辨率是 1080x1920)

ipad不管是哪代 都是 768 x 1024 或者 1024 x 768

视频尺寸
3.5寸 无视频 无需上传
ipad 900x1200 或者 1200 x 900
4.7寸 750x1334 或者 1334 x 750
5.5寸和4寸都可以用 1080x1920 或者 1920 x 1080
App图标:需要1024*1024(像素)的图片

苹果客户电话:中国大陆:400 670 1855
中国香港:21129966
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容

  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,236评论 7 249
  • 杂记: 1.安装Xcode插件管理终端命令: curl -fsSL https://raw.githubuserc...
    suncorex阅读 234评论 0 1
  • 终于见到了中国陶瓷艺术大师、中国龙泉青瓷烧制技术非物质文化遗产传承人之一陈爱明先生。静坐品茗,相聊甚欢,观赏大师作...
    Helenkeller阅读 1,301评论 0 1
  • 感恩阿勋老师传授浇水的神奇心法!感恩我的搭档伙伴沈晓燕、清纯、安静的声音陪伴!感恩高海燕班长无私❤️的付出! ...
    静美63阅读 199评论 0 0
  • 昨天,一个许久不联系的高中同学突然微信里调侃我,说20多年了,还有人对你念念不忘呢。 她这样说,我马上想到一个男生...
    真冉阅读 272评论 1 4