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

<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来检测数字和链接。

UIDataDetectorTypePhoneNumber

UIDataDetectorTypeLink

UIDataDetectorTypeNone

UIDataDetectorTypeAll


通过设置dataDetectorTypes属性就可以实现功能

- (void)viewDidLoad {

     self.textView.dataDetectorTypes = UIDataDetectorTypeAll;

  }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值