UINavigationController之标题歪了
NSArray *VCArray = [self.navigationController viewControllers];
long beforeVCNumber = [VCArray indexOfObject:self] - 1;
UIViewController *beforeVC;
if (beforeVCNumber >= 0) {
beforeVC = [VCArray objectAtIndex:beforeVCNumber];
beforeVC.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@""style:UIBarButtonItemStylePlain target:self action:nil];
}
倒计时时间计算
long long day = countdown / (24*60*60);
long long hour = (countdown % (24*60*60))/(60*60);
long long minute = (countdown - (24*60*60)*day-hour*60*60)/60;
long long second = countdown - 24*60*60*day-hour*60*60-minute*60;
打印方法优化
#define NSLog(FORMAT, ...) fprintf(stderr, "位置:%s %d行 \n内容:%s\n\n", [[[NSString stringWithUTF8String: __FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat: FORMAT, ## __VA_ARGS__] UTF8String])
字典转model,设置model属性快捷输入@property
+ (void)propertyCodeWithDictinoray:(NSDictionary *)dic{
NSMutableString *muStr = [NSMutableString string];
[dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSString *str;
NSLog(@"%@",[obj class]);
if ([obj isKindOfClass:NSClassFromString(@"__NSCFString")] || [obj isKindOfClass:NSClassFromString(@"NSTaggedPointerString")] || [obj isKindOfClass:NSClassFromString(@"__NSCFConstantString")]) {
str = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",key];
}
if ([obj isKindOfClass:NSClassFromString(@"__NSCFNumber")]) {
str = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",key];
}
if ([obj isKindOfClass:NSClassFromString(@"__NSCFArray")] || [obj isKindOfClass:NSClassFromString(@"__NSArrayI")]) {
str = [NSString stringWithFormat:@"@property (nonatomic, copy) NSArray *%@;",key];
}
if ([obj isKindOfClass:NSClassFromString(@"__NSCFDictionary")]) {
str = [NSString stringWithFormat:@"@property (nonatomic, copy) NSDictionary *%@;",key];
}
if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]) {
str = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",key];
}
[muStr appendFormat:@"\n%@\n",str];
}];
NSLog(@"%@",muStr);
}
添加日历时间并返回标记
+ (void)addEventNotify:(NSInteger )afterNum title:(NSString *)title AndEventBlock:(EventIndetifierBlock)eventBlock
{
NSDateFormatter *hdateFormatter=[[NSDateFormatter alloc] init];
[hdateFormatter setDateFormat:@"HH"];
NSDateFormatter *mdateFormatter=[[NSDateFormatter alloc] init];
[mdateFormatter setDateFormat:@"mm"];
NSDateFormatter *sdateFormatter=[[NSDateFormatter alloc] init];
[sdateFormatter setDateFormat:@"ss"];
NSString *hs = [hdateFormatter stringFromDate:[NSDate date]];
NSString *ms = [mdateFormatter stringFromDate:[NSDate date]];
NSString *ss = [sdateFormatter stringFromDate:[NSDate date]];
NSInteger fiveNum = 17 *3600;
NSInteger endDateNum;
if (hs.integerValue <= 17) {
endDateNum = fiveNum - ([hs integerValue] * 60*60 + [ms integerValue]*60 + ss.integerValue);
afterNum = afterNum + endDateNum;
}else{
endDateNum = ([hs integerValue] * 60*60 + [ms integerValue]*60 + ss.integerValue) - fiveNum;
afterNum = afterNum - endDateNum;
}
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:afterNum];
//生成事件数据库对象
EKEventStore *eventDB = [[EKEventStore alloc] init];
//申请事件类型权限
[eventDB requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {
if (granted) { //授权是否成功
EKEvent *myEvent = [EKEvent eventWithEventStore:eventDB]; //创建一个日历事件
myEvent.title = title; //标题
myEvent.startDate = date; //开始date required
myEvent.endDate = date; //结束date required
myEvent.URL = [NSURL URLWithString:@"cn.youxnet.mqqb://miqiqianbao"];
myEvent.notes = @"cn.youxnet.mqqb://miqiqianbao";
[myEvent addAlarm:[EKAlarm alarmWithAbsoluteDate:date]]; //添加一个闹钟 optional
[myEvent addAlarm:[EKAlarm alarmWithRelativeOffset:60 * -1.0]];
[myEvent setCalendar:[eventDB defaultCalendarForNewEvents]]; //添加calendar required
NSError *err;
[eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err]; //保存
if (err) {
NSLog(@"失败");
if (eventBlock) {
eventBlock(@"失败");
}
}else{
NSLog(@"%@",myEvent.eventIdentifier);
// [YOLOToast showSuccessWithStatus:@"提交成功 "];
if (eventBlock) {
eventBlock(myEvent.eventIdentifier);
}
}
}else{
if (eventBlock) {
eventBlock(@"false");
}
}
}];
}
UILabel滚动方式之来回滚动
+ (void)startAnimationIfNeededWith:(UILabel *)titleLabel WithFont:(NSInteger)font{
//自定义高度
CGSize size = [titleLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}];
if (size.width > (kScreen_Width - kFloat(100))) {
[titleLabel setFrame:CGRectMake(0, 0, size.width, kYFloat(60))];
float offset = size.width - kScreen_Width + kFloat(100);
[UIView animateWithDuration:10
delay:0
options:UIViewAnimationOptionRepeat //动画重复的主开关
|UIViewAnimationOptionAutoreverse //动画重复自动反向,需要和上面这个一起用
|UIViewAnimationOptionCurveLinear //动画的时间曲线,滚动字幕线性比较合理
animations:^{
titleLabel.transform = CGAffineTransformMakeTranslation(offset, 0);
}
completion:^(BOOL finished) {
}
];
}
}
UILabel滚动之循环滚动
+ (void)startAnimationIfNeededWith:(UILabel *)titleLabel WithFont:(NSInteger)font{
//自定义高度
CGSize size = [titleLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}];
if (size.width > (kScreen_Width - kFloat(100))) {
[titleLabel setFrame:CGRectMake(0, 0, size.width, kYFloat(60))];
CGRect frame = titleLabel.frame;
frame.origin.x = 20;
titleLabel.frame = frame;
[UIView beginAnimations:@"testAnimation" context:NULL];
[UIView setAnimationDuration:20];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:9999999999];
frame = titleLabel.frame;
frame.origin.x = - size.width;
titleLabel.frame = frame;
[UIView commitAnimations];
}
}
十六进制带透明度的颜色值
+ (UIColor *)UIColorFromHexColor:(NSString *)hexColor Andalpha:(CGFloat )alpha
{
unsigned int red,green,blue;
NSRange range;
range.length = 2;
range.location = 0;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
range.location = 2;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
range.location = 4;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:alpha];
}