//系統(tǒng)左滑手勢禁用

  • (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) {// 沒有高亮選擇的字崇棠,則對已輸入的文字進行字數統(tǒng)計和限制
        if (toBeString.length > length) textField.text = [toBeString substringToIndex:length];
    } else {}// 有高亮選擇的字符串,則暫不對文字進行統(tǒng)計和限制
} else {// 中文輸入法以外的直接對其統(tǒng)計限制即可,不考慮其他語種情況
    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(@"只執(zhí)行一次刷新");
});

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];

去監(jiān)聽方法里判斷 代理實現了沒有:
if ([self.delegate respondsToSelector:@selector(appCellDonw:)]) {
[self.delegate appCellDonw:self];
}
//高亮狀態(tài)下的圖片 用原來的 不渲染
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)#>]創(chuàng)建有自帶圖形的按鈕

[self.view endEditing:YES];
退出鍵盤

//  簡單動畫第一種方式: 頭尾式
//  開始動畫
[UIView beginAnimations:nil context:nil];
//  設置動畫持續(xù)的時間,參數的單位是s
[UIView setAnimationDuration:2];
//  需要執(zhí)行動畫的代碼
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 重復執(zhí)行 某方法
[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; // 

//重復執(zhí)行

  • (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);
//設置按鈕的圖片

設置狀態(tài)欄開始(SB里設置)隱藏 S 再顯示 還有白色

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    application.statusBarHidden = NO;
    application.statusBarStyle = UIStatusBarStyleLightContent;
    return YES;
    }

Pch $(SRCROOT)/ / .PCH

執(zhí)行動畫 圖片
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];

//如果子類要調用父類的方法創(chuàng)建自己類 記得父類創(chuàng) 時 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;
    }

//隱藏狀態(tài)欄
-(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.取消選中狀態(tài)
    [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;圓角

//添加監(jiān)聽手勢
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 代理 聽點擊了個 添加事件 在微博 發(fā)送那個aah
工具條里

關于badgevalue
//通常寫定時器轴捎, 監(jiān)聽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以下鹤盒,不能執(zhí)行下面方法

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];
// 定時器,要執(zhí)行昨悼,要添加到主運行循環(huán),默認NSTimer就會添加到主運行循環(huán)

warning 要執(zhí)行UI操作(拖動表格)的過程中蝗锥,定時器也要執(zhí)行,要設置主運行循環(huán)的一個模式(NSRunLoopCommonModes)

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

定義一個屬性
@property (nonatomic,assign) UIBackgroundTaskIdentifier beforeTaskId;

pragma 程序進入到后臺會進入這個方法

-(void)applicationDidEnterBackground:(UIApplication *)application{

// 把之前任務結束
[application endBackgroundTask:self.beforeTaskId];

// 讓程序開始一個后臺任務率触,讓NSTimer執(zhí)行

warning 這個任務可能在任意一個時刻被程序停止

// 成功開啟后臺任務终议,會返回任務的ID

UIBackgroundTaskIdentifier taskId = [application beginBackgroundTaskWithExpirationHandler:^{
// 當任務被停止的時候調用,結束后臺任務,釋放資源
[application endBackgroundTask:taskId];
}];
self.beforeTaskId = taskId;
}
applicationWillResignActive
即將失去焦點 后臺播放靜音小音樂無限放 可以不停止程序

// 使用 autolayout代碼設置關閉autresizing
blueView.translatesAutoresizingMaskIntoConstraints = NO;
redView.translatesAutoresizingMaskIntoConstraints = NO;

按鈕 間加分隔線 [微博的 6天最后 ]

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末葱蝗,一起剝皮案震驚了整個濱河市穴张,隨后出現的幾起案子,更是在濱河造成了極大的恐慌两曼,老刑警劉巖皂甘,帶你破解...
    沈念sama閱讀 206,214評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現場離奇詭異悼凑,居然都是意外死亡偿枕,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 88,307評論 2 382
  • 文/潘曉璐 我一進店門户辫,熙熙樓的掌柜王于貴愁眉苦臉地迎上來渐夸,“玉大人,你說我怎么就攤上這事渔欢∧顾” “怎么了?”我有些...
    開封第一講書人閱讀 152,543評論 0 341
  • 文/不壞的土叔 我叫張陵奥额,是天一觀的道長苫幢。 經常有香客問我,道長垫挨,這世上最難降的妖魔是什么韩肝? 我笑而不...
    開封第一講書人閱讀 55,221評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮九榔,結果婚禮上哀峻,老公的妹妹穿的比我還像新娘。我一直安慰自己帚屉,他們只是感情好谜诫,可當我...
    茶點故事閱讀 64,224評論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著攻旦,像睡著了一般喻旷。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上牢屋,一...
    開封第一講書人閱讀 49,007評論 1 284
  • 那天且预,我揣著相機與錄音槽袄,去河邊找鬼。 笑死锋谐,一個胖子當著我的面吹牛遍尺,可吹牛的內容都是我干的。 我是一名探鬼主播涮拗,決...
    沈念sama閱讀 38,313評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼乾戏,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了三热?” 一聲冷哼從身側響起鼓择,我...
    開封第一講書人閱讀 36,956評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎就漾,沒想到半個月后呐能,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 43,441評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡抑堡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 35,925評論 2 323
  • 正文 我和宋清朗相戀三年摆出,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片首妖。...
    茶點故事閱讀 38,018評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡偎漫,死狀恐怖,靈堂內的尸體忽然破棺而出悯搔,到底是詐尸還是另有隱情骑丸,我是刑警寧澤舌仍,帶...
    沈念sama閱讀 33,685評論 4 322
  • 正文 年R本政府宣布妒貌,位于F島的核電站,受9級特大地震影響铸豁,放射性物質發(fā)生泄漏灌曙。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,234評論 3 307
  • 文/蒙蒙 一节芥、第九天 我趴在偏房一處隱蔽的房頂上張望在刺。 院中可真熱鬧,春花似錦头镊、人聲如沸蚣驼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽颖杏。三九已至,卻和暖如春坛芽,著一層夾襖步出監(jiān)牢的瞬間留储,已是汗流浹背翼抠。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留获讳,地道東北人阴颖。 一個月前我還...
    沈念sama閱讀 45,467評論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像丐膝,于是被迫代替她去往敵國和親量愧。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 42,762評論 2 345

推薦閱讀更多精彩內容