iOS 總結(jié)

1桌粉,打印View所有子視圖

po [[self view]recursiveDescription]

2.阿拉伯?dāng)?shù)字轉(zhuǎn)漢字(1轉(zhuǎn)一)

原值:2.7999999999
typedef CF_ENUM(CFIndex, CFNumberFormatterRoundingMode) {
    kCFNumberFormatterRoundCeiling = 0,//四舍五入,直接輸出3
    kCFNumberFormatterRoundFloor = 1,//保留小數(shù)輸出2.8
    kCFNumberFormatterRoundDown = 2,//加上了人民幣標(biāo)志,原值輸出¥2.8
    kCFNumberFormatterRoundUp = 3,//本身數(shù)值乘以100后用百分號(hào)表示,輸出280%
    kCFNumberFormatterRoundHalfEven = 4,//輸出2.799999999E0
    kCFNumberFormatterRoundHalfDown = 5,//原值的中文表示,輸出二點(diǎn)七九九九甲葬。储玫。。脆烟。
    kCFNumberFormatterRoundHalfUp = 6//原值中文表示,輸出第三
};


NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:12]];
NSLog(@"str = %@", string);

//阿拉伯?dāng)?shù)字轉(zhuǎn)中文格式
+(NSString *)translation:(NSString *)arebic
{
    NSString *str = arebic;
    NSArray *arabic_numerals = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"0"];
    NSArray *chinese_numerals = @[@"一",@"二",@"三",@"四",@"五",@"六",@"七",@"八",@"九",@"零"];
    NSArray *digits = @[@"個(gè)",@"十",@"百",@"千",@"萬(wàn)",@"十",@"百",@"千",@"億",@"十",@"百",@"千",@"兆"];
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:chinese_numerals forKeys:arabic_numerals];
    
    NSMutableArray *sums = [NSMutableArray array];
    for (int i = 0; i < str.length; i ++) {
        NSString *substr = [str substringWithRange:NSMakeRange(i, 1)];
        NSString *a = [dictionary objectForKey:substr];
        NSString *b = digits[str.length -i-1];
        NSString *sum = [a stringByAppendingString:b];
        if ([a isEqualToString:chinese_numerals[9]])
        {
            if([b isEqualToString:digits[4]] || [b isEqualToString:digits[8]])
            {
                sum = b;
                if ([[sums lastObject] isEqualToString:chinese_numerals[9]])
                {
                    [sums removeLastObject];
                }
            }else
            {
                sum = chinese_numerals[9];
            }
            
            if ([[sums lastObject] isEqualToString:sum])
            {
                continue;
            }
        }
        
        [sums addObject:sum];
    }
    
    NSString *sumStr = [sums componentsJoinedByString:@""];
    NSString *chinese = [sumStr substringToIndex:sumStr.length-1];
    NSLog(@"%@",str);
    NSLog(@"%@",chinese);
    return chinese;
}

3.app內(nèi)啟動(dòng)用戶評(píng)價(jià)

//app內(nèi)啟動(dòng)用戶評(píng)價(jià)
NSString *url = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",490062954];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
490062954是程序的Apple ID,可以在iTunes Connect中查到。
比如在用戶使用一段時(shí)間后,彈出一個(gè)對(duì)話框提醒用戶去評(píng)價(jià):

NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"去給'%@'打分吧壮虫!",appName]
                                                    message:@"您的評(píng)價(jià)對(duì)我們很重要"
                                                   delegate:self
                                          cancelButtonTitle:nil
                                          otherButtonTitles:@"稍后評(píng)價(jià)",@"去評(píng)價(jià)",nil];
[alertView show];



軟件版本: NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];

//iOS跳轉(zhuǎn)到App Store下載應(yīng)用評(píng)分
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APPID"]];

4.字典->模型 模型->字典

//這是使用系統(tǒng)的方法 descriptionDe 代替 description(不使用MJ)
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"description"]) {
        self.descriptionDe = value;
    }
}

1. JSON -> Model【最簡(jiǎn)單的字典轉(zhuǎn)模型】
// JSON -> User
User *user = [User mj_objectWithKeyValues:dict];

2.JSONString -> Model【JSON字符串轉(zhuǎn)模型】
// 1.Define a JSONString
NSString *jsonString = @"{\"name\":\"Jack\", \"icon\":\"lufy.png\", \"age\":20}";

// 2.JSONString -> User
User *user = [User mj_objectWithKeyValues:jsonString];

3.模型中的屬性名和字典中的key不相同(用ID代替id,后面類似)
[Student mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
    return @{
             @"ID" : @"id",
             @"desc" : @"desciption",
             @"oldName" : @"name.oldName",
             @"nowName" : @"name.newName",
             @"nameChangedTime" : @"name.info[1].nameChangedTime",
             @"bag" : @"other.bag"
             };
}];

4.JSON array -> model array【將一個(gè)字典數(shù)組轉(zhuǎn)成模型數(shù)組】

NSArray *userArray = [User mj_objectArrayWithKeyValuesArray:dictArray];

#pragma mark -模型->字典
5.Model -> JSON【將一個(gè)模型轉(zhuǎn)成字典】

Status *status = [[Status alloc] init];
NSDictionary *statusDict = status.mj_keyValues;

6. Model array -> JSON array【將一個(gè)模型數(shù)組轉(zhuǎn)成字典數(shù)組】

NSArray *dictArray = [User mj_keyValuesArrayWithObjectArray:userArray];

7.轉(zhuǎn)化為JSONNString

[dict mj_JSONNString]

5.關(guān)于push,pop,model,dimiss

遍歷popToViewController跳轉(zhuǎn)的控制器环础,然后跳到指定位置
for (int i = 0; i<self.navigationController.viewControllers.count; i++) {
    
    UIViewController * controller = self.navigationController.viewControllers[i];
    
    if ([controller isKindOfClass:InformMainViewController.class]) {
        
        InformMainViewController * vc = (InformMainViewController *)controller;
        
        [self.navigationController popToViewController:vc animated:YES];
        
        break;
        
    }
}

pop回指定控制器

1. NSArray *viewControllers=[self.navigationController viewControllers];
2. UIViewController *controller=[viewControllers objectAtIndex:1];
3. [self.navigationController popToViewController:controller animated:YES];


3.關(guān)于push,pop,model,dimiss
   1.注意?:如果用stroyboard的話囚似,要拉線,不然可能會(huì)出現(xiàn)不了界面O叩谩H幕健!
[self performSegueWithIdentifier:@"MyApply-To-FlowDetail" sender:nil];
//跳轉(zhuǎn)前傳值
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"MyApply-To-FlowDetail"]) {
        FlowDetailController * controller = segue.destinationViewController;
        if (_bool_fromApply) {
            controller.flow_id = _flow_id;
        }
        else
        {
            controller.flow_id = _flowInfoModel.id;
        }
        controller.delegate = self;
    }
}
   2.第二種方法
UIStoryboard *story = [UIStoryboard storyboardWithName:@"My" bundle:nil];
MyEnterCompanyNameController *vc = (MyEnterCompanyNameController *)[story instantiateViewControllerWithIdentifier:@"MyEnterCompanyName"];

[self.navigationController pushViewController:vc animated:YES];

4.設(shè)置轉(zhuǎn)場(chǎng)動(dòng)畫(huà)modalTransitionStyle
 
   1.系統(tǒng)的
UIViewController *detailViewController = [[UIViewController alloc] init];
        detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;    // 設(shè)置動(dòng)畫(huà)效果
        [self presentModalViewController:detailViewController animated:YES];

   2.自定義的
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"My" bundle:nil];
        MyJoinCompanyController *vc = (MyJoinCompanyController *)[storyboard instantiateViewControllerWithIdentifier:@"MyJoinCompanyController"];
CATransition *animation = [CATransition animation];
        [animation setDuration:0.5];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromRight];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [[vc.view layer] addAnimation:animation forKey:@"pushToView"];
        [self presentViewController:vc animated:YES completion:nil];

5.如果底部有tabbar的話贯钩,push要加上
vc.hidesBottomBarWhenPushed = YES;

6.如果拖拽手勢(shì)返回的時(shí)候募狂,右上角有黑色办素,加這句
self.na

6.關(guān)于通知,delegate

1.delegate執(zhí)行回調(diào)pop時(shí)祸穷,如果跨界面跳需要用NSNotificationCenter通知性穿,(代理只能執(zhí)行跳一個(gè)界面!!!!!),
  第2種方法是目標(biāo)控制器.h中聲明一種方法來(lái)調(diào)用

7.判斷app程序第一次啟動(dòng)方法

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]){
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];
    NSLog(@"第一次啟動(dòng)");
}else{
    NSLog(@"不是第一次啟動(dòng)");
}

8.透明度

1.如果UIView B為半透明, 如何讓加載上邊的UIView C不透明?
設(shè)置ViewB的半透明時(shí)使用B.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8]

2. 有透明度的顏色
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
[UIColor colorWithWhite:1.0 alpha:0.2];
[[UIColor whiteColor] colorWithAlphaComponent:0.2];

9.用這方法可以遮住導(dǎo)航欄

[[UIApplication sharedApplication].keyWindow addSubview:self.view_shadow];

10.關(guān)于NSLog

1.點(diǎn)輸出NSLog(@"point  = %@",NSStringFromCGPoint(self.tableView.contentOffset));

11.NULL雷滚、nil需曾、Nil這三者對(duì)于Objective-C中值是一樣的,都是(void *)0祈远,那么為什么要區(qū)分呢胯舷?又與NSNull之間有什么區(qū)別:

NULL是宏,是對(duì)于C語(yǔ)言指針而使用的绊含,表示空指針
nil是宏桑嘶,是對(duì)于Objective-C中的對(duì)象而使用的,表示對(duì)象為空
Nil是宏躬充,是對(duì)于Objective-C中的類而使用的逃顶,表示類指向空
NSNull是類類型,是用于表示空的占位對(duì)象充甚,與JS或者服務(wù)端的null類似的含意

12.NSDate的比較

NSDate *now = [[NSDate alloc] init];
if ([self.btn_date.date compare:now] == NSOrderedDescending) {  // 前面的大于后面的
    
    
}

BOOL result = [a compare:b];
if (result == NSOrderedSame) { // NSOrderedSame = 0 完全一樣
    NSLog(@"a = b");
}else if(result == NSOrderedAscending) // NSOrderedAscending = -1
NSLog(@"a < b");
else{ //NSOrderedDescending = +1
    NSLog(@"a > b");
}

13.關(guān)于Masonry

1.更新可以用update 或者 remake(移除之前的所有約束以政,然后添加新約束的方法是:mas_remakeConstraints。)
2.對(duì)于cell中需要添加刪除變化cell位置的要用mas_remakeConstraints來(lái)設(shè)置約束伴找,(因?yàn)樗翘砑蛹s束與更新約束盈蛮,不用會(huì)有問(wèn)題!)

3.設(shè)置多行l(wèi)abl技矮!
-(void)mostLineLabel
{
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:17];
    label.text = @"Masonry是一個(gè)輕量級(jí)的布局框架與更好的包裝AutoLayout語(yǔ)法抖誉。Masonry是一個(gè)輕量級(jí)的布局框架與更好的包裝AutoLayout語(yǔ)法。asasadadadada";
    label.textColor = [UIColor blackColor];
    [self.view addSubview:label];
    label.numberOfLines = 0;
    
    //注意:這2句很重要
    label.preferredMaxLayoutWidth = ([UIScreen mainScreen].bounds.size.width -20);
    [label setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    //注意:這里只是設(shè)置了它的寬度和位置衰倦,(沒(méi)有設(shè)置高L宦!7恪N掖拧!)
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).with.offset(10);
        make.right.mas_equalTo(self.view).with.offset(-10);
        make.top.mas_equalTo(self.view).with.offset(100);
    }];
}
4.當(dāng)使用masonry自定義cell的時(shí)候驻襟,如果cell的子控件尺寸需要?jiǎng)討B(tài)變化的話夺艰,必須使用remake

14.layoutSubviews在以下情況下會(huì)被調(diào)用:

1、init初始化不會(huì)觸發(fā)layoutSubviews
2沉衣、addSubview會(huì)觸發(fā)layoutSubviews
3郁副、設(shè)置view的Frame會(huì)觸發(fā)layoutSubviews,當(dāng)然前提是frame的值設(shè)置前后發(fā)生了變化
4厢蒜、滾動(dòng)一個(gè)UIScrollView會(huì)觸發(fā)layoutSubviews
5霞势、旋轉(zhuǎn)Screen會(huì)觸發(fā)父UIView上的layoutSubviews事件
6烹植、改變一個(gè)UIView大小的時(shí)候也會(huì)觸發(fā)父UIView上的layoutSubviews事件

15.點(diǎn)擊屏幕得時(shí)候隱藏鍵盤(pán)斑鸦,可以在這個(gè)方法里執(zhí)行要隱藏或remove的view愕贡。

1.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch=[[event allTouches] anyObject];
    if (touch.tapCount >=1) {
        [self.view endEditing:YES];
    }
}
2.你可以在任何地方加上這句話,可以用來(lái)統(tǒng)一收起鍵盤(pán)
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

3.iOS在當(dāng)前屏幕獲取第一響應(yīng)
UIWindow * keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView * firstResponder = [keyWindow performSelector:@selector(firstResponder)];

16.設(shè)置不自動(dòng)黑屏

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

17.如何獲取手機(jī)硬件信息巷屿?

[[UIDevice currentDevice] systemName];
[[UIDevice currentDevice] systemVersion];//os version
[[UIDevice currentDevice] uniqueIdentifier];
[[UIDevice currentDevice] model];
[[UIDevice currentDevice] name];

這樣就實(shí)現(xiàn)了基本的使用固以,跟delegate類似,注意 addObserver時(shí)嘱巾,需要寫(xiě)目標(biāo)viewcontroller的實(shí)例憨琳,而不是self。

18.ios如何實(shí)現(xiàn)推送通知

http://blog.csdn.net/ios_che/article/details/7428413

19.ios9關(guān)于http 與HTTPS

在info.plist最后加上
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
定位功能
<key>NSLocationAlwaysUsageDescription</key>
<string>LocationDemo</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>

20.在iOS上present一個(gè)半透明的viewController

(http://blog.csdn.net/jasonblog/article/details/17172969)
                                  
1. viewController.view.backgroundColor = [UIColor clearColor];
2. rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
3. [rootViewController presentModalViewController:viewController animated:YES];
4. 這里有兩個(gè)點(diǎn):一是設(shè)置modalPresentationStyle為UIModalPresentationCurrentContext旬昭,二是需要在rootViewController上操作篙螟。

21.創(chuàng)建漸變色圖層

 -(void)setGradientLayer2
{
    // 創(chuàng)建漸變色圖層
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame       = self.secView.bounds;
    
    gradientLayer.colors = @[
                             (id)[UIColor cyanColor].CGColor,
                             (id)[UIColor blueColor].CGColor,
                             (id)[UIColor redColor].CGColor
                             ];
    // 設(shè)置漸變方向(0~1)
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0, 1);
    
    // 設(shè)置漸變色的起始位置和終止位置(顏色的分割點(diǎn))
    gradientLayer.locations = @[@(0.05f),@(0.70f),@(0.25f)];
    gradientLayer.borderWidth  = 0.0;
    
    // 添加圖層
    [self.secView.layer addSublayer:gradientLayer];
}

22.svn 無(wú)法上傳.a文件

 去終端:cd 靜態(tài)庫(kù)所在的文件夾路徑 按回車 svn add 你靜態(tài)庫(kù)的名字 .a也需要加上 然后回車

23.設(shè)置center和size,要先設(shè)置size再設(shè)置centerN示小1槁浴!

24.讓iOS應(yīng)用直接退出

- (void)exitApplication {
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    UIWindow *window = app.window;
    
    [UIView animateWithDuration:1.0f animations:^{
        window.alpha = 0;
    } completion:^(BOOL finished) {
        exit(0);
    }];
}

25.獲取 iOS 路徑的方法

1.獲取家目錄路徑的函數(shù)
NSString *homeDir = NSHomeDirectory();

2.獲取Documents目錄路徑的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];

3.獲取Documents目錄路徑的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];

4.獲取tmp目錄路徑的方法:
NSString *tmpDir = NSTemporaryDirectory();

26.修改Tabbar Item的屬性

 // 修改標(biāo)題位置
 self.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -10);
 // 修改圖片位置
 self.tabBarItem.imageInsets = UIEdgeInsetsMake(-3, 0, 3, 0);
 
 // 批量修改屬性
 for (UIBarItem *item in self.tabBarController.tabBar.items) {
     [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIFont fontWithName:@"Helvetica" size:19.0], NSFontAttributeName, nil]
                         forState:UIControlStateNormal];
 }
 
 // 設(shè)置選中和未選中字體顏色
 [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
 
 //未選中字體顏色
 [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} forState:UIControlStateNormal];
 
 //選中字體顏色
 [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor cyanColor]} forState:UIControlStateSelected];

27.UIAlertController

 UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
 
 [controller addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"點(diǎn)擊了[收藏]按鈕");
}]];
 
 [controller addAction:[UIAlertAction actionWithTitle:@"舉報(bào)" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"點(diǎn)擊了[舉報(bào)]按鈕");
}]];
 
 [controller addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"點(diǎn)擊了[取消]按鈕");
}]];
 
 //    [controller addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
 //        textField.textColor = [UIColor redColor];
 //    }];
 
 [self.window.rootViewController presentViewController:controller animated:YES completion:nil];

28.控件的局部圓角問(wèn)題

 1.
 CGRect rect = CGRectMake(0, 0, 100, 50);
 CGSize radio = CGSizeMake(5, 5);//圓角尺寸
 UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//這只圓角位置
 UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
 CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//創(chuàng)建shapelayer
 masklayer.frame = button.bounds;
 masklayer.path = path.CGPath;//設(shè)置路徑
 button.layer.mask = masklayer;
 
 //2.設(shè)置cell為圓角
 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(tintColor)]) {
        if (tableView == self.tableView) {
            // 圓角弧度半徑
            CGFloat cornerRadius = 20.f;
            // 設(shè)置cell的背景色為透明骤坐,如果不設(shè)置這個(gè)的話绪杏,則原來(lái)的背景色不會(huì)被覆蓋
            cell.backgroundColor = UIColor.clearColor;
            
            // 創(chuàng)建一個(gè)shapeLayer
            CAShapeLayer *layer = [[CAShapeLayer alloc] init];
            CAShapeLayer *backgroundLayer = [[CAShapeLayer alloc] init]; //顯示選中
            // 創(chuàng)建一個(gè)可變的圖像Path句柄,該路徑用于保存繪圖信息
            CGMutablePathRef pathRef = CGPathCreateMutable();
            // 獲取cell的size
            CGRect bounds = CGRectInset(cell.bounds, 0, 0);
            
            // CGRectGetMinY:返回對(duì)象頂點(diǎn)坐標(biāo)
            // CGRectGetMaxY:返回對(duì)象底點(diǎn)坐標(biāo)
            // CGRectGetMinX:返回對(duì)象左邊緣坐標(biāo)
            // CGRectGetMaxX:返回對(duì)象右邊緣坐標(biāo)
            
            // 這里要判斷分組列表中的第一行纽绍,每組section的第一行蕾久,每組section的中間行
            BOOL addLine = NO;
            // CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
            
            NSInteger num = [tableView numberOfRowsInSection:indexPath.section];
            if (num == 1) {//1.當(dāng)這組只有一行的時(shí)候,4個(gè)角讀要是圓角
                
                
                // 初始起點(diǎn)為cell的左下角坐標(biāo)
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                // 起始坐標(biāo)為左下角拌夏,設(shè)為p1僧著,(CGRectGetMinX(bounds), CGRectGetMinY(bounds))為左上角的點(diǎn),設(shè)為p1(x1,y1)障簿,(CGRectGetMidX(bounds), CGRectGetMinY(bounds))為頂部中點(diǎn)的點(diǎn)霹抛,設(shè)為p2(x2,y2)。然后連接p1和p2為一條直線l1卷谈,連接初始點(diǎn)p到p1成一條直線l杯拐,則在兩條直線相交處繪制弧度為r的圓角。
                
                //1.左下角為起點(diǎn)p世蔗,左上角為p1端逼,頂部中點(diǎn)為p2,然后連接p1和p2為一條直線l1污淋,連接初始點(diǎn)p到p1成一條直線l顶滩,則在兩條直線相交處繪制弧度為r的圓角。
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                //2.頂部中點(diǎn)為p2寸爆,右上角為p3礁鲁,右邊中點(diǎn)為p4盐欺,連接p2p3與p3p4則在兩條直線相交處繪制弧度為r的圓角。
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMinX(bounds), CGRectGetMidY(bounds), cornerRadius);
                
            }else//2.這組不止1行
            {
                if (indexPath.row == 0) {
                    // 初始起點(diǎn)為cell的左下角坐標(biāo)
                    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                    // 起始坐標(biāo)為左下角仅醇,設(shè)為p1冗美,(CGRectGetMinX(bounds), CGRectGetMinY(bounds))為左上角的點(diǎn),設(shè)為p1(x1,y1)析二,(CGRectGetMidX(bounds), CGRectGetMinY(bounds))為頂部中點(diǎn)的點(diǎn)粉洼,設(shè)為p2(x2,y2)。然后連接p1和p2為一條直線l1叶摄,連接初始點(diǎn)p到p1成一條直線l属韧,則在兩條直線相交處繪制弧度為r的圓角。
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                    // 終點(diǎn)坐標(biāo)為右下角坐標(biāo)點(diǎn)蛤吓,把繪圖信息都放到路徑中去,根據(jù)這些路徑就構(gòu)成了一塊區(qū)域了
                    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                    addLine = YES;
                } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                    // 初始起點(diǎn)為cell的左上角坐標(biāo)
                    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                    // 添加一條直線那先,終點(diǎn)坐標(biāo)為右下角坐標(biāo)點(diǎn)并放到路徑中去
                    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
                } else {
                    // 添加cell的rectangle信息到path中(不包括圓角)
                    CGPathAddRect(pathRef, nil, bounds);
                    addLine = YES;
                }
                
            }
            
            //            if (indexPath.row == 0) {
            //                // 初始起點(diǎn)為cell的左下角坐標(biāo)
            //                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
            //                // 起始坐標(biāo)為左下角谈飒,設(shè)為p1,(CGRectGetMinX(bounds), CGRectGetMinY(bounds))為左上角的點(diǎn),設(shè)為p1(x1,y1)衩茸,(CGRectGetMidX(bounds), CGRectGetMinY(bounds))為頂部中點(diǎn)的點(diǎn)盾舌,設(shè)為p2(x2,y2)淮菠。然后連接p1和p2為一條直線l1爹耗,連接初始點(diǎn)p到p1成一條直線l,則在兩條直線相交處繪制弧度為r的圓角艾岂。
            //                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
            //                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
            //                // 終點(diǎn)坐標(biāo)為右下角坐標(biāo)點(diǎn)顺少,把繪圖信息都放到路徑中去,根據(jù)這些路徑就構(gòu)成了一塊區(qū)域了
            //                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
            //                addLine = YES;
            //            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
            //                // 初始起點(diǎn)為cell的左上角坐標(biāo)
            //                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
            //                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
            //                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
            //                // 添加一條直線,終點(diǎn)坐標(biāo)為右下角坐標(biāo)點(diǎn)并放到路徑中去
            //                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
            //            } else {
            //                // 添加cell的rectangle信息到path中(不包括圓角)
            //                CGPathAddRect(pathRef, nil, bounds);
            //                addLine = YES;
            //            }
            
            
            // 把已經(jīng)繪制好的可變圖像路徑賦值給圖層王浴,然后圖層根據(jù)這圖像path進(jìn)行圖像渲染render
            layer.path = pathRef;
            backgroundLayer.path = pathRef;
            // 注意:但凡通過(guò)Quartz2D中帶有creat/copy/retain方法創(chuàng)建出來(lái)的值都必須要釋放
            CFRelease(pathRef);
            // 按照shape layer的path填充顏色脆炎,類似于渲染render
            // layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;
            layer.fillColor = [UIColor whiteColor].CGColor;
            // 添加分隔線圖層
            if (addLine == YES) {
                CALayer *lineLayer = [[CALayer alloc] init];
                CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
                lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);
                // 分隔線顏色取自于原來(lái)tableview的分隔線顏色
                lineLayer.backgroundColor = tableView.separatorColor.CGColor;
                [layer addSublayer:lineLayer];
            }
            
            // view大小與cell一致
            UIView *roundView = [[UIView alloc] initWithFrame:bounds];
            // 添加自定義圓角后的圖層到roundView中
            [roundView.layer insertSublayer:layer atIndex:0];
            roundView.backgroundColor = UIColor.clearColor;
            //cell的背景view
            //cell.selectedBackgroundView = roundView;
            cell.backgroundView = roundView;
            
            //以上方法存在缺陷當(dāng)點(diǎn)擊cell時(shí)還是出現(xiàn)cell方形效果,因此還需要添加以下方法
            UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:bounds];
            backgroundLayer.fillColor = tableView.separatorColor.CGColor;
            [selectedBackgroundView.layer insertSublayer:backgroundLayer atIndex:0];
            selectedBackgroundView.backgroundColor = UIColor.clearColor;
            cell.selectedBackgroundView = selectedBackgroundView;
        }
    }
}

29.添加毛玻璃效果

 - (void)setupBlur
{
    // 1.初始化toolBar
    UIToolbar *toolBar = [[UIToolbar alloc] init];
    [self.image addSubview:toolBar];
    toolBar.barStyle = UIBarStyleBlack;
    
    // 2.添加約束
    toolBar.translatesAutoresizingMaskIntoConstraints = NO;
    [toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.image);
    }];
}
 
 
 2.
 UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
 imageView.image = [UIImage imageNamed:@"肚肚.jpg"];
 
/*注:盡量避免將UIVisualEffectView對(duì)象的alpha值設(shè)置為小于1.0的值氓辣,
    因?yàn)閯?chuàng)建半透明的視圖會(huì)導(dǎo)致系統(tǒng)在離屏渲染時(shí)去對(duì)UIVisualEffectView對(duì)象
     及所有的相關(guān)的子視圖做混合操作秒裕。這不但消耗CPU/GPU,也可能會(huì)導(dǎo)致許多效果
     顯示不正確或者根本不顯示钞啸。*/
 UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
 view.frame = CGRectMake(20, 20, CGRectGetWidth(self.view.frame)-40,  CGRectGetHeight(self.view.frame)-40);
 view.layer.cornerRadius = 5;
 view.clipsToBounds = YES;
 
 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, CGRectGetWidth(self.view.frame) - 10, 45)];
 label.text = @"fucking high";
 
 [self.view addSubview:imageView];
 [view.contentView addSubview:label];
 [self.view addSubview:view];

30.修改名字

點(diǎn)擊名字几蜻,右鍵,refactor,rename

31.pch文件

1.修改路徑 build setting体斩,apple LLVM 7.0 -Language,Prefix Header
  使用路徑:067/PrefixHeader.pch(相對(duì)路徑)
  全路徑:/Users/bona/Desktop/IOS素材/模板/總結(jié)/搜索search/067/067/PrefixHeader.pch
2.格式
#ifdef __OBJC__  //在這里定義

#define ScreenHeight [[UIScreen mainScreen] bounds].size.height

#endif

32.兩種方法刪除NSUserDefaults所有記錄

//方法一
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];


//方法二
- (void)resetDefaults
{
    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
    NSDictionary * dict = [defs dictionaryRepresentation];
    for (id key in dict)
    {
        [defs removeObjectForKey:key];
    }
    [defs synchronize];
}

33.iOS 獲取漢字的拼音

+ (NSString *)transform:(NSString *)chinese
{
    //將NSString裝換成NSMutableString
    NSMutableString *pinyin = [chinese mutableCopy];
    //將漢字轉(zhuǎn)換為拼音(帶音標(biāo))
    CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
    NSLog(@"%@", pinyin);
    //去掉拼音的音標(biāo)
    CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
    NSLog(@"%@", pinyin);
    //返回最近結(jié)果
    return pinyin;
}

34.手動(dòng)更改iOS狀態(tài)欄的顏色

- (void)setStatusBarBackgroundColor:(UIColor *)color
{
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)])
    {
        statusBar.backgroundColor = color;
    }
}

2.[self setNeedsStatusBarAppearanceUpdate];

3.修改statusbar文字顏色
    1.要修改為白色的需要在infoPlist里設(shè)置UIViewControllerBasedStatusBarAppearance為NO
    2.[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

4.iOS加載啟動(dòng)圖的時(shí)候隱藏statusbar    只需需要在info.plist中加入Status bar is initially hidden 設(shè)置為YES就好

35.取消UICollectionView的隱式動(dòng)畫(huà)

UICollectionView在reloadItems的時(shí)候梭稚,默認(rèn)會(huì)附加一個(gè)隱式的fade動(dòng)畫(huà),有時(shí)候很討厭絮吵,尤其是當(dāng)你的cell是復(fù)合cell的情況下(比如cell使用到了UIStackView)弧烤。
下面幾種方法都可以幫你去除這些動(dòng)畫(huà)


//方法一
[UIView performWithoutAnimation:^{
    [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
}];

//方法二
[UIView animateWithDuration:0 animations:^{
    [collectionView performBatchUpdates:^{
        [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
    } completion:nil];
}];

//方法三
[UIView setAnimationsEnabled:NO];
[self.trackPanel performBatchUpdates:^{
    [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
} completion:^(BOOL finished) {
    [UIView setAnimationsEnabled:YES];
}];

36.獲取到webview的高度

CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];

37.+ initialize 與 +load

+ initialize  這個(gè)方法會(huì)在 第一次初始化這個(gè)類之前 被調(diào)用,我們用它來(lái)初始化靜態(tài)變量

+ load  方法會(huì)在加載類的時(shí)候就被調(diào)用蹬敲,也就是 ios 應(yīng)用啟動(dòng)的時(shí)候暇昂,就會(huì)加載所有的類莺戒,就會(huì)調(diào)用每個(gè)類的 + load 方法,它調(diào)用比main還早

如果你實(shí)現(xiàn)了+ load 方法,那么當(dāng)類被加載時(shí)它會(huì)自動(dòng)被調(diào)用急波。這個(gè)調(diào)用非常早从铲。如果你實(shí)現(xiàn)了一個(gè)應(yīng)用或框架的 + load,并且你的應(yīng)用鏈接到這個(gè)框架上了幔崖,那么 + load 會(huì)在 main() 函數(shù)之前被調(diào)用食店。如果你在一個(gè)可加載的 bundle 中實(shí)現(xiàn)了 + load渣淤,那么它會(huì)在 bundle 加載的過(guò)程中被調(diào)用赏寇。

+ initialize 方法的調(diào)用看起來(lái)會(huì)更合理,通常在它里面寫(xiě)代碼比在 + load 里寫(xiě)更好价认。+ initialize 很有趣嗅定,因?yàn)樗菓姓{(diào)用的,也有可能完全不被調(diào)用用踩。類第一次被加載時(shí)渠退,

+ initialize 不會(huì)被調(diào)用。類接收消息時(shí)脐彩,運(yùn)行時(shí)會(huì)先檢查 + initialize 有沒(méi)有被調(diào)用過(guò)碎乃。如果沒(méi)有,會(huì)在消息被處理前調(diào)用惠奸。

38.自動(dòng)布局scrollview

1.在scrollview上先加一個(gè)contentView
2.設(shè)置它的布局
[self. contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.scrollView);
        make.height.mas_equalTo(800);
    }];
3.所有的子控件添加到contentView梅誓,并基于它來(lái)布局
4.注意:如果沒(méi)有設(shè)置contentView的寬,子控件right要基于self.view佛南,不然會(huì)看不到梗掰,這是由于scrollview的contentSize的width不確定
5. contentView的寬高決定了scrollview的contentSize的width和height

39.編輯狀態(tài)

//1.成為第一響應(yīng)者,叫起鍵盤(pán)
[self.textView becomeFirstResponder];

//2.放棄第一響應(yīng)者嗅回,放下鍵盤(pán)
[self.textView resignFirstResponder];

//3.判斷鍵盤(pán)是否彈起及穗,是否在編輯狀態(tài)
self.textView.isFirstResponder == YES

40.edgesForExtendedLayout

在iOS 7中,蘋(píng)果引入了一個(gè)新的屬性绵载,叫做[UIViewController setEdgesForExtendedLayout:]埂陆,它的默認(rèn)值為UIRectEdgeAll。當(dāng)你的容器是navigation controller時(shí)娃豹,默認(rèn)的布局將從navigation bar的頂部開(kāi)始焚虱。這就是為什么所有的UI元素都往上漂移了44pt。

self.edgesForExtendedLayout = UIRectEdgeNone;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末培愁,一起剝皮案震驚了整個(gè)濱河市著摔,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌定续,老刑警劉巖谍咆,帶你破解...
    沈念sama閱讀 217,406評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件禾锤,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡摹察,警方通過(guò)查閱死者的電腦和手機(jī)恩掷,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)供嚎,“玉大人黄娘,你說(shuō)我怎么就攤上這事】说危” “怎么了逼争?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,711評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)劝赔。 經(jīng)常有香客問(wèn)我誓焦,道長(zhǎng),這世上最難降的妖魔是什么着帽? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,380評(píng)論 1 293
  • 正文 為了忘掉前任杂伟,我火速辦了婚禮,結(jié)果婚禮上仍翰,老公的妹妹穿的比我還像新娘赫粥。我一直安慰自己,他們只是感情好予借,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布越平。 她就那樣靜靜地躺著,像睡著了一般蕾羊。 火紅的嫁衣襯著肌膚如雪喧笔。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,301評(píng)論 1 301
  • 那天龟再,我揣著相機(jī)與錄音书闸,去河邊找鬼。 笑死利凑,一個(gè)胖子當(dāng)著我的面吹牛浆劲,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播哀澈,決...
    沈念sama閱讀 40,145評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼牌借,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了割按?” 一聲冷哼從身側(cè)響起膨报,我...
    開(kāi)封第一講書(shū)人閱讀 39,008評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后现柠,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體院领,經(jīng)...
    沈念sama閱讀 45,443評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評(píng)論 3 334
  • 正文 我和宋清朗相戀三年够吩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了比然。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,795評(píng)論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡周循,死狀恐怖强法,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情湾笛,我是刑警寧澤饮怯,帶...
    沈念sama閱讀 35,501評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站迄本,受9級(jí)特大地震影響硕淑,放射性物質(zhì)發(fā)生泄漏课竣。R本人自食惡果不足惜嘉赎,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望于樟。 院中可真熱鬧公条,春花似錦、人聲如沸迂曲。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,731評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)路捧。三九已至关霸,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間杰扫,已是汗流浹背队寇。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,865評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留章姓,地道東北人佳遣。 一個(gè)月前我還...
    沈念sama閱讀 47,899評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像凡伊,于是被迫代替她去往敵國(guó)和親零渐。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容