0. set方法赋值不上
- 无关其他,是用sd_layout框架设置frame有问题。
1.移除父控件上的说有子view
[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
2.Xcode log 不完整
#ifdef DEBUG
#define CSLog(format, ...) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )
#else
#define CSLog(format, ...)
#endif
3. UIImage 图片拉伸方法
- (UIImage *)resizableImage:(NSString *)name
{
UIImage *image = [UIImage imageNamed:name];
return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
}
4.字符串截取信息
NSUInteger loc = [string rangeOfString:@"\":\""].location + 3;
NSUInteger len = [string rangeOfString:@"\"}"].location - loc;
NSString *msg = [string substringWithRange:NSMakeRange(loc, len)];
5.URL 中的中文转化
NSString *encodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// 上面方法已经废弃
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:name1];
NSString *abc = [name1 stringByAddingPercentEncodingWithAllowedCharacters:set];
- 解码:把str字符串以UTF-8规则进行解码 , UTF-8 转化中文
[str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// 上面的已经废弃
str.stringByRemovingPercentEncoding
//////////
NSString *urlStr = [NSString stringWithFormat:@"http://localhost/login?username=喝喝&pwd=123"];
urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
6.数组顺序和添加的时候到过来
NSArray* reversedArray = [[self.keyRecordData reverseObjectEnumerator] allObjects];
7.退出键盘
[self.view endEditing:YES];
[self.messageField resignFirstResponder];
[self.messageField endEditing:YES];
8.打电话
NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",twoModel.UserPhone];
UIWebView *callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
[self.view addSubview:callWebview];
9. 获取版本号
NSString *appVersion =[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
10. __weak
__weak UITextField * weakTf = textField;
11 获取文字高度
CGFloat h = [model.message boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - kGAP-kAvatar_Size - 2*kGAP, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.height+0.5;
12 section
_dataArray = @[@{ @"key":@"基本信息",
@"value":@[@"姓名",@"性别",@"年龄",@"身高(cm)",@"体重(kg)"],
},
@{ @"key":@"疾病信息",
@"value":@[@"诊断哮喘日期/年龄",@"首次诊断的日期"],
},
@{ @"key":@"过敏原结果",
@"value":@[@"尘螨过敏",@"吸入物过敏",@"食物过敏"],
},
@{ @"key":@"肺功能",
@"value":@[@"支气管舒张试验",@"支气管激发试验"],
}
];
13 使用xib给label 换行快捷键
14 过滤空格
//过滤掉输入框输入的文字前后的空格
NSString *textString = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
15 absoluteString
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/search?id=1"];
2
NSLog(@"scheme:%@", [url scheme]); //协议 http
3
NSLog(@"host:%@", [url host]); //域名 www.baidu.com
4
NSLog(@"absoluteString:%@", [url absoluteString]); //完整的url字符串 http://www.baidu.com:8080/search?id=1 (刚才在真机上跑了一下,并没有打印出来端口 8080 啊)
5
NSLog(@"relativePath: %@", [url relativePath]); //相对路径 search
6
NSLog(@"port :%@", [url port]); // 端口 8080
7
NSLog(@"path: %@", [url path]); // 路径 search
8
NSLog(@"pathComponents:%@", [url pathComponents]); // search
9
NSLog(@"Query:%@", [url query]); //参数 id=1
16 UICollectionView flowlayout 固定item的设置
CGFloat margin = (kScreenWidth - ZKCommonCollectionHW *3)/4.0;
//每行之间竖直之间的最小间距 (可以大于) 设置垂直间距
flowLayout.minimumLineSpacing = margin;
//同行的cell与cell之间水平之间的最小间距(可以) 设置水平间距
flowLayout.minimumInteritemSpacing = margin;
flowLayout.itemSize = CGSizeMake(ZKCommonCollectionHW,ZKCommonCollectionHW);
// 设置整个collectionView的内边距 相对于 上左下右的偏移量
flowLayout.sectionInset = UIEdgeInsetsMake(margin, margin, margin*3 , margin);
// 或者可以使用sdlayout 设置frame 时 就可以不用底部insert 乘以3倍了。
既
_collectionView.sd_layout.spaceToSuperView(UIEdgeInsetsZero);
则
flowLayout.sectionInset = UIEdgeInsetsMake(margin, margin, margin , margin);
17 APP首次和更新后的启动
// NO 没有
- (BOOL)hasLaunched {
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (![[userDefaults objectForKey:@"version"] isEqualToString:version]) {
[userDefaults setObject:version forKey:@"version"];
return NO;
}else {
return YES;
}
}
网友评论