随笔分类 - Objective-C
OC学习的一些Tips
摘要:step1:关闭Xcode step2:打开终端执行 重启Xcode。all is done
阅读全文
摘要:```
//根据已知的label宽度计算文字高度
CGRect rect = [reson boundingRectWithSize:CGSizeMake(label_W, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:kTextFont} context:nil];
CGFloa...
阅读全文
摘要:在终端中,cd项目根目录,输入命令: 按下回车就会显示所有代码行数,如果想除去第三方库代码,可以cd到自己的文件夹目录下。 列出每个文件的行数: 列出代码行数总和(grep v "^$"是去掉空行):
阅读全文
摘要:1、MVVM 的优点 MVVM 兼容 MVC,可以先创建一个简单的 View Model,再慢慢迁移。 MVVM 使得 app 更容易测试,因为 View Model 部分不涉及 UI。 MVVM 最好配合 binding 机制,Model 的变化需要同步到 View Model,View Mode
阅读全文
摘要:```
//获取手机当前显示的ViewController
- (UIViewController*)currentViewController{ UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController; while (1) { if ([vc isK...
阅读全文
摘要:```
// 读取本地JSON文件
- (NSDictionary *)readLocalFileWithName:(NSString *)name { // 获取文件路径 NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"json"]; // 将文件数据化 NSData *d...
阅读全文
摘要:```
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSCharacterSet *charSet = [[NSCharacterSet characterSetWithCharac...
阅读全文
摘要://查找字符串是否包含“心”
阅读全文
摘要:我们使用Xcode8新建的工程,默认支持的最低系统是iOS8,我们可以手动更改版本到7.0,但是不支持真机调试。 现在的项目一般都要兼容iOS7系统,同时也要兼容iOS10,在Xcode8上面,默认情况下无法调试iOS7,因为缺乏调试iOS7需要的配置文件。同时在低版本的Xcode上面(8以下),也
阅读全文
摘要:```
- (NSDictionary *)dataArrayFromJson { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"decoration" ofType:@"json"]; NSString *jsonStr = [NSString stringWithContentsOfFile:fil...
阅读全文
摘要:当修饰可变类型的属性时,如NSMutableArray、NSMutableDictionary、NSMutableString,用strong。 当修饰不可变类型的属性时,如NSArray、NSDictionary、NSString,用copy。
阅读全文
摘要:```
// //把“***”垂直居中
// NSMutableAttributedString *ats = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"**** **** **** %@",bankNumber]];
// [ats add...
阅读全文
摘要:```
NSString *hanziText = @"今天天气不错"; if ([hanziText length]) { NSMutableString *ms = [[NSMutableString alloc] initWithString:hanziText]; if (CFStringTransform((__bridge CFMutableStringRe...
阅读全文
摘要:URL传递数据中,如果含有中文,需要进行编码: 接收到数据后,需要进行解码处理:
阅读全文
摘要:这里是使用了KVC的方式,是不是很简单呢
阅读全文
摘要:1、一次性修改一个scope里的变量名: 点击该变量,出现下划虚线,然后command+control+E激活所有相同变量,然后进行修改。 2、删除一个词:option+delete 删除一句话:command+delete 3、快捷搜索: 先点亮想要搜索的词,然后command+E将该次放入剪贴板
阅读全文
摘要:此方法用来计算当前时间与目标时间的先后顺序: 将时区转为当前时区 判断当天是星期几:
阅读全文
摘要:给你一个方法,输入参数是NSDate,输出结果是星期几的字符串。+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @
阅读全文
摘要:[NSDate date]获取的是GMT时间,要想获得某个时区的时间,以下代码可以解决这个问题 NSDate *date = [NSDate date]; NSTimeZone *zone = [NSTimeZone systemTimeZone]; NSInteger interval = [zo
阅读全文