Skip to content

Instantly share code, notes, and snippets.

View monsoir's full-sized avatar

Monsoir monsoir

View GitHub Profile
[UIImage imageNamed: [[[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectForKey:@"CFBundlePrimaryIcon"] objectForKey:@"CFBundleIconFiles"] objectAtIndex:0]]
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?20:0)){
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -10;//这个数值可以根据情况自由变化
self.navigationItem.rightBarButtonItems = @[negativeSpacer,itemAdd, itemSearch];
} else {
self.navigationItem.rightBarButtonItems = @[itemAdd, itemSearch];
}
scrollView.automaticallyAdjustsScrollViewInsets = NO;
//获取当前时间
NSDate *now = [NSDate date];
//设置日期格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddHHmmssSSS"];
//获取日期字符串
NSString *dateString = [dateFormatter stringFromDate:now];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponents = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:[[NSDate alloc] init]];
[dateComponents setMonth:dateComponents.month - 1];
NSDate *lastMonthDate = [calendar dateFromComponents:dateComponents];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyyMM";
lastMonthDateString = [dateFormatter stringFromDate:lastMonthDate];
// 其实就是一个shadow image
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
// Create Regular Expression
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:<# 正则表达式 #> options:<# 选项 #> error:&error];
// Counting the number of matches in a given range of a string
NSUInteger numberOfMatches = [regex numberOfMatchesInString:<# 需要检查的字符串 #> option:<# NSMatchingOptions #> range:<# 检查的范围 #>];
// Get the first match range and the string, method 1
NSRange rangeOfFirstMatch = [regex rangeOfFirstMatchInString:<# 需要检查的字符串 #> options:0 range:NSMakeRange(0, [<# 需要检查的字符串 #> length])];
if (!NSEqualRanges(rangeOfFirstMatch, NSMakeRange(NSNotFound, 0))) {
//创建并初始化一个 UIBarButtonItem 实例
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView: btn];
//再将 item 与 导航栏 关联起来
self.navigationItem.leftBarButton = item;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
<# ... your code here ... #>
#pragma clang diagnostic pop
NSData *jsonData = [<# 需要转换的 JSON 字符串 #> dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];