大杂烩(二)


笑笑语法:@ nsnumber           @123@{} dictionariy       @{k1:1,k2:2}@“” string              @"wo"@[] array                @[@"1",@"2"]  @() expression  //数字       @(1)

{

//对于navigationbar上面颜色字体颜色的修改

 UIFont *font = [UIFont systemFontOfSize:19.f];
    NSDictionary *textAttributes = @{
                                     NSFontAttributeName : font,
                                     NSForegroundColorAttributeName : [UIColor greenColor]
                                     };
    [[UINavigationBar appearance] setTitleTextAttributes:textAttributes];//设置navigationbar  tittle 的颜色
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];  //设置leftbarbuttonitem  的颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];  //设置navigationbar的颜色


    //修改系统自带的navigationItem的rightBarButtonItem的颜色

  UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"下一页" style:UIBarButtonItemStyleBordered target:nil action:nil];
    self.navigationItem.rightBarButtonItem = rightBarItem;
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor redColor];

}


对于UISearchBar的backgroundImage取消操作,只需要在你创建的UISearchBar里面添加如下代码:

          [searchBarsetBackgroundImage:[[UIImagenew]init]];
   
searchBar . translucent = NO ;
   
searchBar . layer . cornerRadius = 10.0;
 
                searchBar . layer . borderColor = [ UIColor     lightGrayColor ]. CGColor ;
   
searchBar . layer . masksToBounds = YES ;
 
                searchBar . layer . borderWidth = 1;

//查看设备的版本

NSUInteger DeviceSystemMajorVersion();

NSUInteger DeviceSystemMajorVersion() {
    
    static NSUInteger _deviceSystemMajorVersion = -1;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        _deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
        
    });
    return _deviceSystemMajorVersion;
    
}

#define MY_MACRO_NAME (DeviceSystemMajorVersion() < 7)



//对数组根据某个属性升序或者降序排序
- (NSArray *)sortArray:(NSArray *)array withPropertyKey:(NSString *)key withBool:(BOOL)ascending
{
    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:key ascending:ascending];
    NSArray *arr = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
    return arr;
}


NSUserDefaults   的建立方法

+(void)setUserdefaultWithValue:(id)value forKey:(NSString *)key
{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setValue:value forKey:key];
    [userDefault synchronize];
}

发送验证码  60秒

_timeOutSecond = 59;

 if (!_timer)
        {
            _timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeOutMethod) userInfo:nil repeats:YES];
            [_timer fire];
            [_achieveBtn setBackgroundImage:[UIImage imageNamed:@"validateNumberClick.png"] forState:UIControlStateNormal];
        }
    }
    
}

//倒计时
-(void)timeOutMethod
{
    [_achieveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_achieveBtn setTitle:[NSString stringWithFormat:@"%@",@(_timeOutSecond)] forState:UIControlStateNormal];
    
    _timeOutSecond--;
    if (_timeOutSecond==0)
    {
        [_timer invalidate];
        _timer=nil;
        
        [_achieveBtn setTitle:@"重新获取验证码" forState:UIControlStateNormal];
        [_achieveBtn setTitleColor:[UIColor colorWithRed:97.0/255.0
                                                   green:173.0/255.0
                                                    blue:46.0/255.0
                                                   alpha:1.0]
                          forState:UIControlStateNormal];
        _achieveBtn.titleLabel.font=[UIFont systemFontOfSize:13.0];
        [_achieveBtn setBackgroundImage:[UIImage imageNamed:@"WaitValidateNumber.png"] forState:UIControlStateNormal];
        _timeOutSecond=60;
        _achieveBtn.userInteractionEnabled=YES;
        _isHighLight=NO;
    }
}

//访问plist文件

//LoanDeadLineModelPlistName是plist文件名    而线面接受的数组是创建plist文件的根目录是什么类型

 NSString *loanDeadLineModlePlist = [[NSBundle mainBundle] pathForResource:LoanDeadLineModelPlistName ofType:@"plist"];
   _anjYearModelData = [[NSMutableArray alloc]initWithContentsOfFile:loanDeadLineModlePlist];



//观察键盘的


        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

- (void)keyboardWillShow:(NSNotification *)notification
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
#endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
        NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
#else
        NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
#endif
        CGRect keyboardBounds;
        [keyboardBoundsValue getValue:&keyboardBounds];
        UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0);
        [[self tableView] setScrollIndicatorInsets:e];
        [[self tableView] setContentInset:e];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
    }
#endif


或者NSDictionary* info = [notification userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;




void)keyboardWillShow:(NSNotification *)notification
{
    NSValue* aValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    NSNumber *durationValue = [notification userInfo][UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration = durationValue.doubleValue;

    [UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        _toolViewBottomConstraint.constant = keyboardRect.size.height;//修改距离底部的约束
    } completion:^(BOOL finished) {
    }];    
    [self.view setNeedsLayout]; //更新视图
    [self.view layoutIfNeeded];

都是获取键盘的大小的
}


#pragma mark - MBProgressHUD
-(void)initHUDView
{
    mbHUD = [[MBProgressHUD alloc]initWithView:self.view];
    mbHUD.mode = MBProgressHUDModeIndeterminate;
    [self.view addSubview:mbHUD];
}

-(void)showLoadingView:(NSString *)message
{
    if (mbHUD) {
        
        mbHUD.labelText = message ? message : @"加载中...";
        [mbHUD show:YES];
    }
}

-(void)hiddenLoadingView
{
    if (mbHUD) {
        [mbHUD hide:YES];
    }
}

#pragma mark - MBProgressHUD
-(void)initOnlyTextHUDView
{
    onlyTextHUD = [[MBProgressHUD alloc]initWithView:self.view];
    onlyTextHUD.mode = MBProgressHUDModeText;
    [self.view addSubview:onlyTextHUD];
}

-(void)showOnlyTextAlertView:(NSString *)message
{
    if (onlyTextHUD) {
        
        onlyTextHUD.labelText = message ? message : @"操作成功";
        [onlyTextHUD show:YES];
        
        [self performSelector:@selector(hiddenOnlyTextAlertView)
                   withObject:nil
                   afterDelay:1.0];
    }
}

-(void)hiddenOnlyTextAlertView
{
    if (onlyTextHUD) {
        [onlyTextHUD hide:YES];
    }
}

#pragma mark - ShowAlert
-(void)showAlertWithTitle:(NSString *)alertTitle andMessage:(NSString *)message
{
    
    UIAlertView *titleAlert = [[UIAlertView alloc]initWithTitle:alertTitle
                                                        message:message
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"确认", nil];
    [titleAlert show];
    
}

#pragma mark - EndRefresh
-(void)endRefreshWithTableView:(UITableView *)tableView
{
    if (tableView.footerRefreshing) {
        
        [tableView footerEndRefreshing];
    }
    if (tableView.headerRefreshing) {
        
        [tableView headerEndRefreshing];
    
    }
}

-(void)initRequestList
{
    [self showLoadingView:@"加载中..."];
    
    [_mainTableView addHeaderWithTarget:self
                                 action:@selector(headerRefreshMethod)];
    [_mainTableView addFooterWithTarget:self
                                 action:@selector(footerRefreshMethod)];
    [self initData];
}
#pragma mark - MJRefreshMethod
-(void)headerRefreshMethod
{
    [self initData];
}

-(void)footerRefreshMethod
{
    [self initData];
}

//时间的方法


+ (NSString *)formatDate:(NSDate *)date format:(NSString *)formatter {
    static NSDateFormatter *dateFormatter = nil;
    
    if (dateFormatter == nil) {
        dateFormatter = [[NSDateFormatter alloc] init];
    }
    
    [dateFormatter setDateFormat:formatter];
    
    return [dateFormatter stringFromDate:date];
}

+ (NSDate *)dateFromString:(NSString *)dateString format:(NSString *)formatter {
    
    static NSDateFormatter *dateFormatter = nil;
    
    if (dateFormatter == nil) {
        dateFormatter = [[NSDateFormatter alloc] init];
    }
    
    [dateFormatter setDateFormat:formatter];
    
    NSDate *destDate= [dateFormatter dateFromString:dateString];
    
    return destDate;
}

- (NSString *)getTimeString:(NSString *)string setDateFormat:(NSString *)dateFormatString{

if (dateFormatter == nil) {
        dateFormatter = [[NSDateFormatter alloc] init];
    }  

if(dateFormatString == nil){

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

}    [dateformatter setDateFormat:dateFormatString];
    NSString *str = [string stringByReplacingOccurrencesOfString:@"/Date(" withString:@""];
    NSString *st = [str stringByReplacingOccurrencesOfString:@")/" withString:@""];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[st longLongValue] / 1000];
    NSString *dateString = [dateformatter stringForObjectValue:date];
    return dateString;
}

//修改placeholder
[self.placeholder drawInRect:CGRectMake(5, 8 + self.contentInset.top, self.frame.size.width-self.contentInset.left, self.frame.size.height- self.contentInset.top) withAttributes:@{NSFontAttributeName:self.font, NSForegroundColorAttributeName:[UIColor redColor], NSParagraphStyleAttributeName:paragraphStyle}]



//去除字符串两边的空格

NSString * str1 =[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值