iOS项目开发经验:【常用代码4】

来源:互联网 发布:图像虚化处理算法 编辑:程序博客网 时间:2024/04/29 16:28

<4-1>获取当前时间

 NSString *nowDateString = [NSDateFormatter localizedStringFromDate:[NSDate date]                                                           dateStyle:NSDateFormatterMediumStyle                                                           timeStyle:NSDateFormatterNoStyle];


<4-2>在子viewController中隐藏tabbar

    viewController.hidesBottomBarWhenPushed = YES;    [self.navigationController pushViewController:viewController animated:YES];


<4-3>查看设备支持的字体:

for (NSString *family in [UIFont familyNames]) {    NSLog(@"%@", family);    for (NSString *fontName in [UIFont fontNamesForFamilyName:family]) {        NSLog(@"\t %@", fontName);    }}


<4-4>开发调试和发布阶段日志控制,打开宏定义

#ifndef __OPTIMIZE__   #define NSLog(...) NSLog(__VA_ARGS__)   #else  #define NSLog(...)#endif  

<4-5>去掉UITableView中Cell之间的分割线

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

<4-6>UITableView滚动到最下面

    - (void)scrollToFoot:(BOOL)animated {          NSInteger section = [self.tableView numberOfSections];          if (section<1) return;          NSInteger row = [self.tableView numberOfRowsInSection:section-1];          if (row<1) return;           NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row-1 inSection:section-1];           [self.tableView scrollToRowAtIndexPath:indexPath                              atScrollPosition:UITableViewScrollPositionBottom                                      animated:animated];      }  



<4-7> UITextView支持超链接,电话

在iPhone 3.0后就支持UIDataDetectorTypes来检测数字和链接。UIDataDetectorTypePhoneNumberUIDataDetectorTypeLinkUIDataDetectorTypeNoneUIDataDetectorTypeAll通过设置dataDetectorTypes属性就可以实现功能- (void)viewDidLoad {     self.textView.dataDetectorTypes = UIDataDetectorTypeAll;  }




原创粉丝点击