//系统左滑手势禁用
(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
去掉空格
NSString *cleaned = [[phoneNr componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@""];
第一步:添加方法:[_moneyTextField addTarget:self action:@selector(whenTextFieldChange:) forControlEvents:UIControlEventEditingChanged];
第二步:实现:
pragma mark textChange事件
-(void)whenTextFieldChange:(UITextField *)textField{
NSString *toBeString = textField.text;
NSInteger length = 4;//限制的字数
if (textField == _moneyTextField) length = 5;//如果是钱输入框限制的字数
// NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
NSString *lang=[[[UIApplication sharedApplication]textInputMode] primaryLanguage];
if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
UITextRange *selectedRange = [textField markedTextRange];//获取当前已经输入的字数
UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];//获取高亮部分
if (!position) {// 没有高亮选择的字,则对已输入的文字进行字数统计和限制
if (toBeString.length > length) textField.text = [toBeString substringToIndex:length];
} else {}// 有高亮选择的字符串,则暂不对文字进行统计和限制
} else {// 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
if (toBeString.length > length) textField.text = [toBeString substringToIndex:length];
}
}
IOS7 textView 光标下偏移问题 //textView 里面的不偏移
self.modalPresentationCapturesStatusBarAppearance = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
UISearchBar searchBar = [UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
for (UIView subview in [[searchBar.subviews lastObject] subviews]) {
if ([subview isKindOfClass:[UITextField class]]) { UITextField textField = (UITextField)subview;
textField.textColor = [UIColor redColor]; //修改输入字体的颜色
[textField setBackgroundColor:[UIColor grayColor]]; //修改输入框的颜色 [textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; //修改placeholder的颜色 } else if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) { [subview removeFromSuperview]; }
//获取当前时间年月日时分秒
NSDate *now = [NSDate date];
NSLog(@”now date is: %@”, now);
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
int year = [dateComponent year];
int month = [dateComponent month];
int day = [dateComponent day];
int hour = [dateComponent hour];
int minute = [dateComponent minute];
int second = [dateComponent second];
NSLog(@”year is: %d”, year);
NSLog(@”month is: %d”, month);
NSLog(@”day is: %d”, day);
NSLog(@”hour is: %d”, hour);
NSLog(@”minute is: %d”, minute);
NSLog(@”second is: %d”, second);
//开机闪图
// 2.3显示TabbarController
SJTabBarController *tabbarContr =[[SJTabBarController alloc]init];
self.window.rootViewController = tabbarContr;
//开机闪图
self.window.rootViewController.view.alpha = 0;
self.imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"start"]];
self.imageView.frame = [UIScreen mainScreen].bounds;
[self.window addSubview:self.imageView];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.window.rootViewController.view.alpha = 1.0;
[self.imageView removeFromSuperview];
});
// [UIView animateWithDuration:5 animations:^{
// self.window.rootViewController.view.alpha = 1.0;
// } completion:^(BOOL finished) {
// [self.imageView removeFromSuperview];
// }];
//限制评论textView字数100字
- (BOOL)textView:(UITextView *)atextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
NSString *new = [self.tv.text stringByReplacingCharactersInRange:range withString:text];
NSInteger res = 100-[new length];
if(res >= 0){
return YES;
}
else{
NSRange rg = {0,[text length]+res};
if (rg.length>0) {
NSString *s = [text substringWithRange:rg];
[self.tv setText:[self.tv.text stringByReplacingCharactersInRange:range withString:s]];
}
return NO;
}
}
f
//ios7不偏移
self.modalPresentationCapturesStatusBarAppearance = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self setupHistory];
NSLog(@"只执行一次刷新");
});
pragma mark - 删除操作
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}-
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.dataArray removeObjectAtIndex:indexPath.row];
// Delete the row from the data source.
[self.tableview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
pragma mark - 删除操作
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}-
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.dataArray removeObjectAtIndex:indexPath.row];
// Delete the row from the data source.
[self.tableview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
pragma mark - 删除操作
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}-
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.dataArray removeObjectAtIndex:indexPath.row];
// Delete the row from the data source.
[self.tableview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
header通过下面两个代理方法设置
(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
footer通过下面两个
(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
如果要做整个tableview的header和footer,要通过tableview setHeaderView setFooterView
判断TBLEView 上下滚动方向
float lastContentOffset;
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
lastContentOffset = scrollView.contentOffset.y;
}(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
if (lastContentOffset < scrollView.contentOffset.y) {
NSLog(@"向上滚动");
}else{
NSLog(@"向下滚动");
}
}
判断本机是否有百度地图高德地图
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]){
hasBaiduMap = YES;
}
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]){
hasGaodeMap = YES;
}
字符串截取问号后面的参数 分割
if ([request.URL.absoluteString hasPrefix:@"http://gz.itcast.cn/auth?code=" ]) {
NSString *code = [request.URL.query componentsSeparatedByString:@"="][1];
去监听方法里判断 代理实现了没有:
if ([self.delegate respondsToSelector:@selector(appCellDonw:)]) {
[self.delegate appCellDonw:self];
}
//高亮状态下的图片 用原来的 不渲染
UIImage *selIMG = [UIImage imageNamed:selectedIMG];
selIMG = [selIMG imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Lable设置圆角
// 设置圆角
// 设置圆角的半径
tipLabel.layer.cornerRadius = 10;
// 超出边界剪掉
// tipLabel.clipsToBounds = YES;
// 使用layer设置超出边界剪掉
tipLabel.layer.masksToBounds = YES;
[UIButton buttonWithType:<#(UIButtonType)#>]创建有自带图形的按钮
[self.view endEditing:YES];
退出键盘
// 简单动画第一种方式: 头尾式
// 开始动画
[UIView beginAnimations:nil context:nil];
// 设置动画持续的时间,参数的单位是s
[UIView setAnimationDuration:2];
// 需要执行动画的代码
self.tankView.center = center;
// 提交动画
[UIView commitAnimations];
帧动画 y
CAeyframeAnimation *anim = [CAKeyframeAnimation animation];
anim.keyPath = @"transform.scale";
anim.values = @[@(0),@(1.4),@(1)];
anim.duration = 0.5;
//错误抖动画
//
CAKeyframeAnimation *shakeAnim = [CAKeyframeAnimation animation];
shakeAnim.keyPath = @"transform.translation.x";
shakeAnim.duration = 0.1;
shakeAnim.values = @[@0,@-10,@10,@0];
shakeAnim.repeatCount = 2;
[self.loginView.layer addAnimation:shakeAnim forKey:nil];
索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [self.carGroups valueForKeyPath:@"title"];
}
//安排每头间隔 1 s 重复执行 某方法
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
//获取当前日历 里面有详细时间
NSCalendar *calendar = [NSCalendar currentCalendar];
//获取当前日历 里面的某些你想要的组件
NSDateComponents *components = [calendar components:NSCalendarUnitHour | NSCalendarUnitMinute |
NSCalendarUnitSecond fromDate:[NSDate date]];
// 2.1 获得当前秒数
NSInteger second = components.second;
// 2.2 获得当前分针数
NSInteger minute = components.minute;
// 2.3 获得当前小时数
NSInteger hour = components.hour; //
//重复执行
(CADisplayLink *)link {
if (_link == nil) {
_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(rota)];
[_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
return _link;
}(void)startRota
{
if (_link) {
return;
}
[self link];
}
//按钮的背景图片
//加载那两张要剪切的图片
UIImage *normalImage = [UIImage imageNamed:@"LuckyAstrology"];
UIImage *lightImage = [UIImage imageNamed:@"LuckyAstrologyPressed"];
//计算要裁剪成小图的Frame 经计算 宽80 高92
CGRect clipFrame = CGRectMake(index * 80, 0, 80, 92);
//裁剪出小图片 传入图片传入Frame
CGImageRef smallImage = CGImageCreateWithImageInRect(normalImage.CGImage, clipFrame);
//设置按钮的图片
设置状态栏开始(SB里设置)隐藏 S 再显示 还有白色
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.statusBarHidden = NO;
application.statusBarStyle = UIStatusBarStyleLightContent;
return YES;
}
Pch $(SRCROOT)/ / .PCH
执行动画 图片
self.lightView.animationImages = @[[UIImage imageNamed:@"lucky_entry_light0@2x"],[UIImage imageNamed:@"lucky_entry_light1@2x"]];
self.lightView.animationDuration = 0.5f;
self.lightView.animationRepeatCount = MAXFLOAT;
[self.lightView startAnimating];
帧动画 变形
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
anim.keyPath = @"transform.scale";
anim.values = @[@(0),@(1.4),@(1)];
anim.duration = 0.5;
//父控件动画 约束
[UIView animateWithDuration:1 animations:^{
[self layoutIfNeeded];
}];
//旋转图片
btn.imageView.transform = CGAffineTransformMakeRotation(M_PI);
[UIView animateWithDuration:0.5 animations:^{
//相对来位置旋转
sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);
}];
//设置BTN的图片不拉伸
//里面的图片不拉伸
leftView.contentMode = UIViewContentModeCenter;
-(void)awakeFromNib
{
self.imageView.contentMode = UIViewContentModeCenter;
}
/** 写死 设置BTN的内容位置
-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
return CGRectMake(82, 0, 16, contentRect.size.height);
}
-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
return CGRectMake(0, 0, 80, contentRect.size.height);
}
*/
//自定义BTN 设置BTN的内容位置
-(void)layoutSubviews
{
//TMD要记得调用
[super layoutSubviews];
//获得按钮的尺寸
CGFloat btnW = self.frame.size.width;
CGFloat btnH = self.frame.size.height;
//获得标题的尺寸
CGFloat titleH = self.titleLabel.frame.size.height;
CGFloat titleW = self.titleLabel.frame.size.width;
//获得图片的尺寸
CGFloat imageW = self.imageView.frame.size.width;
CGFloat imageH = btnH;
CGFloat margin = 5;
CGFloat titleX = (btnW-titleW-margin-imageW)*0.5;
CGFloat imgaX = titleX+titleW+margin;
self.imageView.frame = CGRectMake(imgaX, 0, imageW, imageH);
self.titleLabel.frame = CGRectMake(titleX, 0, titleW, titleH);
}
//返回上一页
[self dismissViewControllerAnimated:YES completion:nil];
sourceController推出destinationController用:
[self.navigationController pushViewController:webViewController animated:YES];
destinationController返回sourceController用:
[self.navigationCo
ntroller popViewControllerAnimated:YES];
//如果子类要调用父类的方法创建自己类 记得父类创 时 self alloc
+(instancetype)itemWithTitle:(NSString *)title icon:(NSString *)icon
{
CZSettingItem *item = [[self alloc]init];
item.title =title;
item.icon = icon;
return item;
?}
// 时间转字符串
NSDateFormatter *formatetter = [[NSDateFormatter alloc]init];
formatetter.dateFormat = @"HH:mm";
NSString *value = [formatetter stringFromDate:date];
//字符串转时间
NSDateFormatter *formatetter = [[NSDateFormatter alloc]init];
formatetter.dateFormat = @"HH:mm";
NSString *startTime = @"10:00";
NSString *endTime = @"12:00";
NSDate *endDate = [formatetter dateFromString:endTime];
NSDate *startDate = [formatetter dateFromString:startTime];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"yyyy-MM-dd";
NSDate *minDate = [formatter dateFromString:@"1915-8-27"];
NSDate *maxDate = [formatter dateFromString:@"2095-8-27"];
解析JSON
NSString *path = [[NSBundle mainBundle]pathForResource:@"help.json" ofType:nil];
NSData *jsonData = [NSData dataWithContentsOfFile:path];
NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
//第一响应者
if ([self.birthField isFirstResponder]) {
[self.placeField becomeFirstResponder];
}
cell的层剪 圆角
- (void)awakeFromNib {
self.productimageCell.layer.cornerRadius = 8.0;
self.productimageCell.layer.masksToBounds = YES;
}
//隐藏状态栏
-(BOOL)prefersStatusBarHidden
{
return YES;
}
设置它的行数
cell.textLabel.numberOfLines = 2;
问题二 如何改变字体的大小?
解决方案:
设置字体大小
cell.textLabel.font = [UIFont systemFontOfSize:12];
问题三 如何改变字体的颜色?
解决方案:
设置字体颜色
cell.textLabel.textColor = [UIColor yellowColor];
问题三 如何改变字体的靠左对齐还是右还是中?
解决方案:
设置字体对齐方式
cell.textLabel.textAlignment = NSTextAlignmentCenter;
设置文字的label的坐标
cell.textLabel.frame = cellFrame;
设置tag值
cell.textLabel.tag =20;
在多数据的时候别忘了调整cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
//开始时cell下移 初始位置
self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
//CELL取消选中 即点击后放手不会高亮
-
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// 0.取消选中状态
[tableView deselectRowAtIndexPath:indexPath animated:YES];}
//获取缓存路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
在Iphone上有两种读取图片数据的简单方法:
UIImageJPEGRepresentation 取UIImage的JPEG格式的NSData
UIImagePNGRepresentation. 取UIImage的PNG格式的NSData
UIImageJPEGRepresentation函数需要两个参数:图片的引用和压缩系数.
// 包括路径" / "拼接
NSString *imgPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:imgName];
self.imageView.layer.cornerRadius = 10;圆角
//添加监听手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panContenView:)];
[contentView addGestureRecognizer:pan];
-(void)panContenView:(UIPanGestureRecognizer *)recognizer{
//获取距离
CGPoint tans = [recognizer translationInView:recognizer.view];
if (recognizer.state == UIGestureRecognizerStateEnded||recognizer.state == UIGestureRecognizerStateCancelled) {
[UIView animateWithDuration:0.2 animations:^{
self.contentView.transform = CGAffineTransformIdentity;
}];
return;
}
//设置平移
self.contentView.transform = CGAffineTransformMakeTranslation(tans.x*0.1, 0);
}
//IMAGEVIEW 的背景颜色 用图片来填充
UIImage *grayStar = [UIImage imageNamed:@"img_star_gray"];
self.starImgView.backgroundColor = [UIColor colorWithPatternImage:grayStar];
应用跳转
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:jumStr8]];
info.plist 添加URLtype indentifier schemes 两个
// 2.获得应用对象
UIApplication *app = [UIApplication sharedApplication];
NSURL *localUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@",product.customUrl,product.Id]];
if ([app canOpenURL:localUrl]) { // 如果能够打开,意味着已经装了该应用
[app openURL:localUrl];
} else {//不能就打开下载地址
NSURL *url = [NSURL URLWithString:product.url];
[app openURL:url];
}
appDelegate.m 有这个获取 到后面参数 的方法QUETY
[Url query]
//获取目标控制器
-
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{TextFieldViewController(目标的类名) *tfVC = segue.destinationViewController;
}
// 根据STORYboard 的名字 实例化一个控制器 跳转
UIStoryboard *SB =[UIStoryboard storyboardWithName:@"ONE" bundle:nil];
UIViewController *VC = [SB instantiateInitialViewController];
[self presentViewController:VC animated:YES completion:nil];
- (IBAction)showPhotoLibrary:(id)sender {
//选择相册的图片图片控制器
UIImagePickerController *imgPickerContr = [[UIImagePickerController alloc] init];
imgPickerContr.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgPickerContr.delegate = self;
[self presentViewController:imgPickerContr animated:YES completion:nil];
}
//选择相册图片调用
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *img = info[UIImagePickerControllerOriginalImage];
self.imgView.image = img;
[self dismissViewControllerAnimated:YES completion:nil];
}
//图片转为二进制数据
NSData *imgData = UIImagePNGRepresentation(self.image);
//文字的尺寸 图片尺寸 image.size.width higth
CGSize maxSize = CGSizeMake(MAXFLOAT, MAXFLOAT);
//属性
UIFont *titleFont = [UIFont systemFontOfSize:16];
CGSize titleSize = [title boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titleFont} context:nil].size;
//设置字体大小
btn.titleLabel.font = titleFont;
btn.bounds = CGRectMake(0, 0, titleSize.width, titleSize.height);
warning 有换行字体尺寸计算要用boundingRectWithSize方法
textAtt = @{NSFontAttributeName:CZStatusOrginalTextFont};
CGSize maxSize = CGSizeMake(UIScreenW - CZStatusCellInset * 2, MAXFLOAT);
CGSize textSize = [status.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:textAtt context:nil].size;
self.textFrm = (CGRect){textX,textY,textSize};
//只有一行字的尺寸
CGSize nameSize = [status.user.screen_name sizeWithAttributes:textAtt];
CGSize sourceSize = [status.source sizeWithAttributes:textAtt];
//计算字体尺寸
//用来装字体的属性
NSMutableDictionary *att = [NSMutableDictionary dictionary];
att[NSFontAttributeName] = self.placeHolderLabel.font;
CGSize placeHolderSize = [self.placeHolder boundingRectWithSize:CGSizeMake(labelW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:att context:nil].size;
//隐藏tabbar
viewController.hidesBottomBarWhenPushed = YES;
//设置全局导航条的格式背景标题
UINavigationBar *navbar = [UINavigationBar appearance];
[navbar setBackgroundImage:[UIImage imageNamed:@"navigationbar_background_os7"] forBarMetrics:UIBarMetricsDefault];
//阴影
NSShadow *shadow =[[NSShadow alloc]init];
shadow.shadowOffset = CGSizeMake(1, 1);
//shadow.shadowColor = [UIColor redColor];
NSDictionary *attr = @{NSFontAttributeName:[UIFont systemFontOfSize:20],NSShadowAttributeName:shadow};
[navbar setTitleTextAttributes:attr];
//沙盒版本号
import "NSUserDefaults+Extention.h"
@implementation NSUserDefaults (Extention)
/**
-
保存当前版本号到偏好设置
*/
+(void)saveCurrentVersionToSandBox{
//获取当前PLIST的版本号 保存NSString *currentVersion = [NSUserDefaults versionFromInfoPlist];
NSUserDefaults defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:currentVersion forKey:@"VersionInSandBox"];
[defaults synchronize];
}
/* -
获取沙盒的版本号
*/
+(NSString *)versionFromSandBox{return [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionInSandBox"];
}
/**
-
获取Info.plist的版本号
*/
+(NSString *)versionFromInfoPlist{
NSDictionary *info = [NSBundle mainBundle].infoDictionary;
NSString *versionKey = (__bridge NSString *) kCFBundleVersionKey;NSString *currentVersion = info[versionKey];
return currentVersion;
}
//sd框架 设置缓存加载图片 占位图 导入#import "UIImageView+WebCache.h"
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:status.user.profile_image_url] placeholderImage:[UIImage imageNamed:@"timeline_card_top_background_highlighted"]];
//自定义NSLog
#ifdef DEBUG //... 可变参数
// #define CZLog(...) NSLog(VA_ARGS)
#define CZLog(...) NSLog(@"%s %d \n %@ \n\n",func,LINE, [NSString stringWithFormat:VA_ARGS]);
#elif
#define CZLog(...)
#endif
//动画更新微博条数
double duration = 1.0;
[UIView animateWithDuration:duration animations:^{
// banner.y += 44;
banner.transform = CGAffineTransformMakeTranslation(0, 44);
} completion:^(BOOL finished) {
[UIView animateWithDuration:duration animations:^{
// banner.y -= 44;
banner.transform = CGAffineTransformIdentity;//恢复原位
} completion:^(BOOL finished) {
// 显示完后移除
[banner removeFromSuperview];
}];
}];
枚举自动绑BTN TAG 代理 听点击了个 添加事件 在微博 发送那个aah
工具条里
关于badgevalue
//通常写定时器, 监听badgevalue 的改变
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(unreadCount) userInfo:nil repeats:YES];
如果是 tabbarcontroller 的item 上显示 要拿到 子控制器设置
UIViewController *nav0 = self.viewControllers[0];//拿到第一个子控制器
if (result.status > 0如果有值) { 设置这个控制器的值 值是字符串 不是要转成
nav0.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",result.status];
}else{
nav0.tabBarItem.badgeValue = nil;
}
// ios8.0 版本号以上才要 添加appIconBadge权限
warning ios7以下,不能执行下面方法
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
[application registerUserNotificationSettings:settings];
}
// 写定时器,
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(unreadCount) userInfo:nil repeats:YES];
// 定时器,要执行,要添加到主运行循环,默认NSTimer就会添加到主运行循环
warning 要执行UI操作(拖动表格)的过程中,定时器也要执行,要设置主运行循环的一个模式(NSRunLoopCommonModes)
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
定义一个属性
@property (nonatomic,assign) UIBackgroundTaskIdentifier beforeTaskId;
pragma 程序进入到后台会进入这个方法
-(void)applicationDidEnterBackground:(UIApplication *)application{
// 把之前任务结束
[application endBackgroundTask:self.beforeTaskId];
// 让程序开始一个后台任务,让NSTimer执行
warning 这个任务可能在任意一个时刻被程序停止
// 成功开启后台任务,会返回任务的ID
UIBackgroundTaskIdentifier taskId = [application beginBackgroundTaskWithExpirationHandler:^{
// 当任务被停止的时候调用,结束后台任务,释放资源
[application endBackgroundTask:taskId];
}];
self.beforeTaskId = taskId;
}
applicationWillResignActive
即将失去焦点 后台播放静音小音乐无限放 可以不停止程序
// 使用 autolayout代码设置关闭autresizing
blueView.translatesAutoresizingMaskIntoConstraints = NO;
redView.translatesAutoresizingMaskIntoConstraints = NO;
按钮 间加分隔线 [微博的 6天最后 ]