记录一下自己常用的方法

有些方法经常在以前项目中找出来再拷贝进去,偶尔遇到u盘没带或者换台电脑,感觉自己都不会写了,这边开一篇来记录一下.一些方法网上也有,但忘记是转自哪里,只能说有雷同请勿怪.

颜色


/** 16进制颜色 */

+ (instancetype)BFColorWithHex:(uint32_t)hex;


/** 随机颜色 */

+ (instancetype)BFRandomColor;


/** rgb颜色 */

+ (instancetype)BFColorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue alpha:(uint8_t)alpha;


/** 以上方法实现 */


+ (instancetype)BFColorWithHex:(uint32_t)hex {

    

    uint8_t red = (hex & 0xff0000) >> 16;

    uint8_t green = (hex & 0x00ff00) >> 8;

    uint8_t blue = hex & 0x0000ff;

    

    return [self BFColorWithRed:red green:green blue:blue alpha:1.0];

}


+ (instancetype)BFRandomColor {

    return [UIColor BFColorWithRed:arc4random_uniform(256) green:arc4random_uniform(256) blue:arc4random_uniform(256) alpha:1.0];

}


+ (instancetype)BFColorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue alpha:(uint8_t)alpha {

    return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:alpha];

}


时间

/*

 获取当前时间

 到年:timeType = @"yyyy"

 到月:timeType = @"yyyy-MM"

 到天:timeType = @"yyyy-MM-dd"

 到小时:timeType = @"yyyy-MM-dd hh"

 到分:timeType = @"yyyy-MM-dd hh:mm"

 到秒:timeType = @"yyyy-MM-dd hh:mm:ss"

 */

+(NSString *)getTimeDateWithType:(NSString *)timeType;



/**

 根据日期获取礼拜几

 传入时间格式要求yyyy-MM-dd

 */

+(NSString *)weekDayStringFromDate:(NSString *)date;



/** 以上方法实现 */

+(NSString *)getTimeDateWithType:(NSString *)timeType{

    NSDate *date = [NSDate date];

    NSTimeInterval interval = [date timeIntervalSinceNow];

    NSDate *timeDate = [[NSDate alloc]initWithTimeIntervalSinceNow:interval];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];

    [dateFormat setDateFormat:timeType];

    NSString *currentTime = [dateFormat stringFromDate:timeDate];

    return currentTime;

}


+(NSString *)weekDayStringFromDate:(NSString *)date{


    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"星期日", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];

    

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];

    

    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];

    

    [calendar setTimeZone: timeZone];

    

    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;

    

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    

    [dateFormatter setDateFormat:@"yyyy-MM-dd"];

    

    NSDate *inputDate = [dateFormatter dateFromString:date];

    

    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];

    

    return [weekdays objectAtIndex:theComponents.weekday];

}

UIAlertController的title和message设置

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"认证失败" message:@"审核失败,可能是以下原因:\n1、个人姓名与身份证不对应\n2、手持照片不清晰\n3、身份证号不正确\n4、身份证假的,ps过,请重新提交认证信息" preferredStyle:UIAlertControllerStyleAlert];

        UIView *subView1 = alert.view.subviews[0];

        UIView *subView2 = subView1.subviews[0];

        UIView *subView3 = subView2.subviews[0];

        UIView *subView4 = subView3.subviews[0];

        UIView *subView5 = subView4.subviews[0];

        //titlemessage

        UILabel *title = subView5.subviews[0];

        UILabel *message = subView5.subviews[1];

        title居中显示

        title.textAlignment = NSTextAlignmentCenter;

message靠左显示

        message.textAlignment = NSTextAlignmentLeft;


UIView添加手势

     //手势方法

    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickSearch:)];

    //view添加手势

    [bgSearchView addGestureRecognizer:tapGesture];

    [tapGesture setNumberOfTapsRequired:1];



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值