笑笑语法:@ 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];
}
//查看设备的版本
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]];