版權(quán)聲明:本文為博主原創(chuàng)文章约计,未經(jīng)博主允許不得轉(zhuǎn)載。
iPhone Size:
手機(jī)型號(hào) | 屏幕尺寸 |
---|---|
iPhone 4 4s | 320 * 480 |
iPhone 5 5s | 320 * 568 |
iPhone 6 6s | 375 * 667 |
iphone 6 plus 6s plus | 414 * 736 |
1.判斷郵箱格式是否正確的代碼:
//利用正則表達(dá)式驗(yàn)證
-(BOOL)isValidateEmail:(NSString *)email
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
return [emailTest evaluateWithObject:email];
}
2.圖片壓縮
用法:UIImage *yourImage= [self imageWithImageSimple:image scaledToSize:CGSizeMake(210.0, 210.0)];
//壓縮圖片
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
// 創(chuàng)建一個(gè)圖形文本
UIGraphicsBeginImageContext(newSize);
//畫(huà)出新文本的尺寸
// new size
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
//從文本上得到一個(gè)新的圖片
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// 結(jié)束編輯文本
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}
3.親測(cè)可用的圖片上傳代碼
//按鈕響應(yīng)事件
- (IBAction)uploadButton:(id)sender {
UIImage *image = [UIImage imageNamed:@"1.jpg"]; //圖片名
NSData *imageData = UIImageJPEGRepresentation(image,0.5);//壓縮比例
NSLog(@"字節(jié)數(shù):%i",[imageData length]);
// post url
NSString *urlString = @"http://192.168.1.113:8090/text/UploadServlet";
//服務(wù)器地址
// setting up the request object now
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
//
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data;boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
//
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition:form-data; name=\"userfile\"; filename=\"2.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //上傳上去的圖片名字
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
// NSLog(@"1-body:%@",body);
NSLog(@"2-request:%@",request);
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"3-測(cè)試輸出:%@",returnString);
4.對(duì)圖庫(kù)的操作
//選擇相冊(cè):
UIImagePickerControllerSourceTypesourceType=UIImagePickerControllerSourceTypeCamera;
if (![UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
}
UIImagePickerController * picker = [[UIImagePickerControlleralloc]init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:YES];
//選擇完畢:
-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage * image=[info objectForKey:UIImagePickerControllerEditedImage];
[self performSelector:@selector(selectPic:) withObject:imageafterDelay:0.1];
}
-(void)selectPic:(UIImage*)image
{
NSLog(@"image%@",image);
imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[self.viewaddSubview:imageView];
[self performSelectorInBackground:@selector(detect:) withObject:nil];
}
//detect為自己定義的方法待逞,編輯選取照片后要實(shí)現(xiàn)的效果
//取消選擇:
-(void)imagePickerControllerDIdCancel:(UIImagePickerController*)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
5.創(chuàng)建一個(gè)UIBarButtonItem右邊按鈕
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右邊" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
[self.navigationItem setRightBarButtonItem:rightButton];
6.設(shè)置navigationBar隱藏
self.navigationController.navigationBarHidden = YES;//```
7.iOS開(kāi)發(fā)之UIlabel多行文字自動(dòng)換行 (自動(dòng)折行)
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 150)];
label.text = @"Hello world! Hello world!Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world! Hello world! Helloworld!";
//自動(dòng)折行設(shè)置
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;```
8.代碼生成button
CGRect frame = CGRectMake(0, 400, 72.0, 37.0);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
[button setTitle:@"新添加的按鈕" forState: UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
button.tag = 2000;
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];```
9.讓某個(gè)控件在View的中心位置顯示:
(某個(gè)控件,比如label,View)label.center = self.view.center;```
10.好看的文字處理
以tableView中cell的textLabel為例子:
cell.backgroundColor = [UIColorscrollViewTexturedBackgroundColor];
//設(shè)置文字的字體
cell.textLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:100.0f];
//設(shè)置文字的顏色
cell.textLabel.textColor = [UIColor orangeColor];
//設(shè)置文字的背景顏色
cell.textLabel.shadowColor = [UIColor whiteColor];
//設(shè)置文字的顯示位置
cell.textLabel.textAlignment = UITextAlignmentCenter;```
11. 隱藏Status Bar
讀者可能知道一個(gè)簡(jiǎn)易的方法,那就是在程序的viewDidLoad中加入
[[UIApplication sharedApplication]setStatusBarHidden:YES animated:NO];```
- 更改AlertView背景
UIAlertView *theAlert = [[[UIAlertViewalloc] initWithTitle:@"Atention"
message: @"I'm a Chinese!"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Okay",nil] autorelease];
[theAlert show];
UIImage *theImage = [UIImageimageNamed:@"loveChina.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:0topCapHeight:0];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(5, 5, theSize.width-10, theSize.height-20)];//這個(gè)地方的大小要自己調(diào)整肤粱,以適應(yīng)alertview的背景顏色的大小冀自。
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
theAlert.layer.contents = (id)[theImage CGImage];```
13.鍵盤(pán)透明
textField.keyboardAppearance = UIKeyboardAppearanceAlert;```
14.狀態(tài)欄的網(wǎng)絡(luò)活動(dòng)風(fēng)火輪是否旋轉(zhuǎn)
[UIApplication sharedApplication].networkActivityIndicatorVisible揉稚,默認(rèn)值是NO。```
15.截取屏幕圖片
//創(chuàng)建一個(gè)基于位圖的圖形上下文并指定大小為CGSizeMake(200,400)
UIGraphicsBeginImageContext(CGSizeMake(200,400));
//renderInContext 呈現(xiàn)接受者及其子范圍到指定的上下文
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
//返回一個(gè)基于當(dāng)前圖形上下文的圖片
UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext();
//移除棧頂?shù)幕诋?dāng)前位圖的圖形上下文
UIGraphicsEndImageContext();
//以png格式返回指定圖片的數(shù)據(jù)
imageData = UIImagePNGRepresentation(aImage);```
16.更改cell選中的背景
UIView *myview = [[UIView alloc] init];
myview.frame = CGRectMake(0, 0, 320, 47);
myview.backgroundColor = [UIColorcolorWithPatternImage:[UIImage imageNamed:@"0006.png"]];
cell.selectedBackgroundView = my view;```
17.能讓圖片適應(yīng)框的大邪敬帧(沒(méi)有確認(rèn))
NSString*imagePath = [[NSBundle mainBundle] pathForResource:@"XcodeCrash"ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];
UIImage *newImage= [image transformWidth:80.f height:240.f];
UIImageView *imageView = [[UIImageView alloc]initWithImage:newImage];
[newImagerelease];
[image release];
[self.view addSubview:imageView];```
18.如果只是想把當(dāng)前頁(yè)面的狀態(tài)欄隱藏的話搀玖,直接用下面的代碼就可以了
[[UIApplication sharedApplication] setStatusBarHidden:TRUE];```
19. 如果是想把整個(gè)應(yīng)用程序的狀態(tài)欄都隱藏掉,操作如下:
在info.plist上添加一項(xiàng):Status bar is initially hidden驻呐,value為YES灌诅;
完后在MainAppDelegate.mm的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法里面加上如下一句就可以了:
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];```
20.增強(qiáng)版NSLog
//A better version of NSLog
define NSLog(format, ...) do { \
fprintf(stderr, "<%s : %d> %s\n",
[[[NSString stringWithUTF8String:FILE] lastPathComponent] UTF8String],
LINE, func);
(NSLog)((format), ##VA_ARGS);
fprintf(stderr, "-------\n");
} while (0)
21.給navigation Bar 設(shè)置 title 顏色
UIColor *whiteColor = [UIColor whiteColor];NSDictionary *dic = [NSDictionary dictionaryWithObject:whiteColor forKey:NSForegroundColorAttributeName];
[self.navigationController.navigationBar setTitleTextAttributes:dic];
22.如何把一個(gè)CGPoint存入數(shù)組里
CGPoint itemSprite1position = CGPointMake(100, 200);NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:NSStringFromCGPoint(itemSprite1position),nil];
// 從數(shù)組中取值的過(guò)程是這樣的
CGPoint point = CGPointFromString([array objectAtIndex:0]);NSLog(@"point is %@.", NSStringFromCGPoint(point));
//可以用NSValue進(jìn)行基礎(chǔ)數(shù)據(jù)的保存,用這個(gè)方法更加清晰明確含末。
CGPoint itemSprite1position = CGPointMake(100, 200);
NSValue *originValue = [NSValue valueWithCGPoint:itemSprite1position];
NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:originValue, nil];
// 從數(shù)組中取值的過(guò)程是這樣的:
NSValue *currentValue = [array objectAtIndex:0];
CGPoint point = [currentValue CGPointValue];
NSLog(@"point is %@.", NSStringFromCGPoint(point));
現(xiàn)在Xcode7后OC支持泛型了猜拾,可以用NSMutableArray<NSString *> *array來(lái)保存。
23.UIColor 獲取 RGB 值
UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
const CGFloat *components = CGColorGetComponents(color.CGColor);
NSLog(@"Red: %f", components[0]);
NSLog(@"Green: %f", components[1]);
NSLog(@"Blue: %f", components[2]);
NSLog(@"Alpha: %f", components[3]);
24.修改textField的placeholder的字體顏色佣盒、大小
self.textField.placeholder = @"username is in here!";
[self.textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[self.textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
25.兩點(diǎn)之間的距離
static inline CGFloat CGPointDistanceBetweenTwoPoints(CGPoint point1, CGPoint point2)
{
CGFloat dx = point2.x - point1.x; CGFloat dy = point2.y - point1.y; return sqrt(dxdx + dydy);
}
26.iOS開(kāi)發(fā)-關(guān)閉/收起鍵盤(pán)方法總結(jié)
//1挎袜、點(diǎn)擊Return按扭時(shí)收起鍵盤(pán)
- (BOOL)textFieldShouldReturn:(UITextField *)textField { return [textField resignFirstResponder]; }
//2、點(diǎn)擊背景View收起鍵盤(pán)(你的View必須是繼承于UIControl)
[self.view endEditing:YES];
//3肥惭、你可以在任何地方加上這句話盯仪,可以用來(lái)統(tǒng)一收起鍵盤(pán)
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
27.在使用 ImagesQA.xcassets 時(shí)需要注意
將圖片直接拖入image到ImagesQA.xcassets中時(shí),圖片的名字會(huì)保留蜜葱。這個(gè)時(shí)候如果圖片的名字過(guò)長(zhǎng)磨总,那么這個(gè)名字會(huì)存入到ImagesQA.xcassets中,名字過(guò)長(zhǎng)會(huì)引起SourceTree判斷異常笼沥。
28.UIPickerView 判斷開(kāi)始選擇到選擇結(jié)束
開(kāi)始選擇的蚪燕,需要在繼承UiPickerView娶牌,創(chuàng)建一個(gè)子類(lèi),在子類(lèi)中重載
- (UIView)hitTest:(CGPoint)point withEvent:(UIEvent)event
當(dāng)[super hitTest:point withEvent:event]
返回不是nil的時(shí)候馆纳,說(shuō)明是點(diǎn)擊中UIPickerView中了诗良。結(jié)束選擇的, 實(shí)現(xiàn)UIPickerView的delegate方法
- (void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
當(dāng)調(diào)用這個(gè)方法的時(shí)候鲁驶,說(shuō)明選擇已經(jīng)結(jié)束了鉴裹。
29.iOS模擬器 鍵盤(pán)事件
當(dāng)iOS模擬器 選擇了Keybaord->Connect Hardware keyboard 后,不彈出鍵盤(pán)钥弯。
//當(dāng)代碼中添加了
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
進(jìn)行鍵盤(pán)事件的獲取径荔。那么在此情景下將不會(huì)調(diào)用- (void)keyboardWillHide
.因?yàn)闆](méi)有鍵盤(pán)的隱藏和顯示。
30.在ios7上使用size classes后上面下面黑色
使用了size classes后脆霎,在ios7的模擬器上出現(xiàn)了上面和下面部分的黑色
可以在General->App Icons and Launch Images->Launch Images Source中設(shè)置Images.xcassets來(lái)解決总处。

31.線程中更新 UILabel的text
[self.label1 performSelectorOnMainThread:@selector(setText:) withObject:textDisplay waitUntilDone:YES];
label1 為UILabel,當(dāng)在子線程中睛蛛,需要進(jìn)行text的更新的時(shí)候鹦马,可以使用這個(gè)方法來(lái)更新。其他的UIView 也都是一樣的忆肾。
32.使用UIScrollViewKeyboardDismissMode實(shí)現(xiàn)了Message app的行為
像Messages app一樣在滾動(dòng)的時(shí)候可以讓鍵盤(pán)消失是一種非常好的體驗(yàn)荸频。然而,將這種行為整合到你的app很難客冈。幸運(yùn)的是旭从,蘋(píng)果給UIScrollView添加了一個(gè)很好用的屬性keyboardDismissMode,這樣可以方便很多场仲。
現(xiàn)在僅僅只需要在Storyboard中改變一個(gè)簡(jiǎn)單的屬性和悦,或者增加一行代碼,你的app可以和辦到和Messages app一樣的事情了燎窘。
這個(gè)屬性使用了新的UIScrollViewKeyboardDismissMode enum枚舉類(lèi)型摹闽。這個(gè)enum枚舉類(lèi)型可能的值如下:
typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode)
{
UIScrollViewKeyboardDismissModeNone,
UIScrollViewKeyboardDismissModeOnDrag, // dismisses the keyboard when a drag begins
UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss
} NS_ENUM_AVAILABLE_IOS(7_0);
以下是讓鍵盤(pán)可以在滾動(dòng)的時(shí)候消失需要設(shè)置的屬性:

33.報(bào)錯(cuò) "_sqlite3_bind_blob", referenced from:
將 sqlite3.dylib加載到framework
34.ios7 statusbar 文字顏色
iOS7上蹄咖,默認(rèn)status bar字體顏色是黑色的褐健,要修改為白色的需要在infoPlist里設(shè)置UIViewControllerBasedStatusBarAppearance為NO,然后在代碼里添加:
[application setStatusBarStyle:UIStatusBarStyleLightContent];
35.獲得當(dāng)前硬盤(pán)空間
NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *fattributes = [fm attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
NSLog(@"容量%lldG",[[fattributes objectForKey:NSFileSystemSize] longLongValue]/1000000000);
NSLog(@"可用%lldG",[[fattributes objectForKey:NSFileSystemFreeSize] longLongValue]/1000000000);
36.給UIView 設(shè)置透明度澜汤,不影響其他sub views
UIView設(shè)置了alpha值蚜迅,但其中的內(nèi)容也跟著變透明。有沒(méi)有解決辦法俊抵?
設(shè)置background color的顏色中的透明度
比如:
[self.testView setBackgroundColor:[UIColor colorWithRed:0.0 green:1.0 blue:1.0 alpha:0.5]];
設(shè)置了color的alpha谁不, 就可以實(shí)現(xiàn)背景色有透明度,當(dāng)其他sub views不受影響給color 添加 alpha徽诲,或修改alpha的值刹帕。
// Returns a color in the same color space as the receiver with the specified alpha component.
- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;
// eg.
[view.backgroundColor colorWithAlphaComponent:0.5];
37.將color轉(zhuǎn)為UIImage
//將color轉(zhuǎn)為UIImage
- (UIImage *)createImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
38.NSTimer 用法
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
在NSRunLoop 中添加定時(shí)器.
38.Bundle identifier 應(yīng)用標(biāo)示符
Bundle identifier 是應(yīng)用的標(biāo)示符吵血,表明應(yīng)用和其他APP的區(qū)別。
39.NSDate 獲取幾年前的時(shí)間
// 獲取到40年前的日期
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setYear:-40];
self.birthDate = [gregorian dateByAddingComponents:dateComponents toDate:[NSDate date] options:0];
40.iOS加載啟動(dòng)圖的時(shí)候隱藏statusbar
只需需要在info.plist中加入Status bar is initially hidden 設(shè)置為YES就好!```
41.iOS 開(kāi)發(fā)偷溺,工程中混合使用 ARC 和非ARC
Xcode 項(xiàng)目中我們可以使用 ARC 和非 ARC 的混合模式蹋辅。
如果你的項(xiàng)目使用的非 ARC 模式,則為 ARC 模式的代碼文件加入 -fobjc-arc 標(biāo)簽挫掏。
如果你的項(xiàng)目使用的是 ARC 模式侦另,則為非 ARC 模式的代碼文件加入 -fno-objc-arc 標(biāo)簽。
添加標(biāo)簽的方法:
打開(kāi):你的target -> Build Phases -> Compile Sources.
雙擊對(duì)應(yīng)的 *.m 文件
在彈出窗口中輸入上面提到的標(biāo)簽 -fobjc-arc / -fno-objc-arc
點(diǎn)擊 done 保存
42.iOS7 中 boundingRectWithSize:options:attributes:context:計(jì)算文本尺寸的使用
之前使用了NSString類(lèi)的sizeWithFont:constrainedToSize:lineBreakMode:方法尉共,但是該方法已經(jīng)被iOS7 Deprecated了褒傅,而iOS7新出了一個(gè)boudingRectWithSize:options:attributes:context方法來(lái)代替。而具體怎么使用呢袄友,尤其那個(gè)attribute.
NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:13]};
CGSize size = [@"相關(guān)NSString" boundingRectWithSize:CGSizeMake(100, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
43.NSDate使用 注意
NSDate 在保存數(shù)據(jù)殿托,傳輸數(shù)據(jù)中,一般最好使用UTC時(shí)間杠河。
在顯示到界面給用戶(hù)看的時(shí)候碌尔,需要轉(zhuǎn)換為本地時(shí)間。
44.在UIViewController中property的一個(gè)UIViewController的Present問(wèn)題
如果在一個(gè)UIViewController A中有一個(gè)property屬性為UIViewController B券敌,實(shí)例化后唾戚,將BVC.view 添加到主UIViewController A.view上,如果在viewB上進(jìn)行
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);
的操作將會(huì)出現(xiàn)待诅,“ **Presenting view controllers on detached view controllers is discouraged **” 的問(wèn)題叹坦。
以為BVC已經(jīng)present到AVC中了,所以再一次進(jìn)行會(huì)出現(xiàn)錯(cuò)誤卑雁。
可以使用
[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:^{ NSLog(@"Finished"); }];
來(lái)解決募书。
45.UITableViewCell indentationLevel 使用
UITableViewCell 屬性 NSInteger indentationLevel 的使用, 對(duì)cell設(shè)置 indentationLevel的值测蹲,可以將cell 分級(jí)別莹捡。
還有 CGFloat indentationWidth; 屬性,設(shè)置縮進(jìn)的寬度扣甲。
總縮進(jìn)的寬度: **indentationLevel * indentationWidth**
46.ActivityViewController 使用AirDrop分享
使用AirDrop 進(jìn)行分享:
NSArray *array = @[@"test1", @"test2"];UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];[self presentViewController:activityVC animated:YES completion:^{ NSLog(@"Air"); }];
就可以彈出界面:
47.獲取CGRect的height
獲取CGRect的height篮赢, 除了self.createNewMessageTableView.frame.size.height
這樣進(jìn)行點(diǎn)語(yǔ)法獲取。
還可以使用CGRectGetHeight(self.createNewMessageTableView.frame)
進(jìn)行直接獲取琉挖。
除了這個(gè)方法還有func CGRectGetWidth(rect: CGRect) -> CGFloat
等等簡(jiǎn)單地方法
func CGRectGetMinX(rect: CGRect) -> CGFloat
func CGRectGetMidX(rect: CGRect) -> CGFloat
func CGRectGetMaxX(rect: CGRect) -> CGFloat
func CGRectGetMinY(rect: CGRect) -> CGFloat
48.打印 %
NSString *printPercentStr = [NSString stringWithFormat:@"%%"];
49.在工程中查看是否使用 IDFA
allentekiMac-mini:JiKaTongGit lihuaxie$ grep -r advertisingIdentifier .
grep: ./ios/Framework/AMapSearchKit.framework/Resources: No such file or directory
Binary file ./ios/Framework/MAMapKit.framework/MAMapKit matches
Binary file ./ios/Framework/MAMapKit.framework/Versions/2.4.1.e00ba6a/MAMapKit matches
Binary file ./ios/Framework/MAMapKit.framework/Versions/Current/MAMapKit matches
Binary file ./ios/JiKaTong.xcodeproj/project.xcworkspace/xcuserdata/lihuaxie.xcuserdatad/UserInterfaceState.xcuserstate matches
allentekiMac-mini:JiKaTongGit lihuaxie$
打開(kāi)終端启泣,到工程目錄中, 輸入:
grep -r advertisingIdentifier .
可以看到那些文件中用到了IDFA示辈,如果用到了就會(huì)被顯示出來(lái)寥茫。
50.APP 屏蔽 觸發(fā)事件
// Disable user interaction when download finishes[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
51.設(shè)置Status bar顏色
status bar的顏色設(shè)置:
如果沒(méi)有navigation bar, 直接設(shè)置
// make status bar background color
self.view.backgroundColor = COLOR_APP_MAIN;
如果有navigation bar矾麻, 在navigation bar 添加一個(gè)view來(lái)設(shè)置顏色纱耻。
// status bar color
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -20, ScreenWidth, 20)];
[view setBackgroundColor:COLOR_APP_MAIN];
[viewController.navigationController.navigationBar addSubview:view];```
52.NSDictionary 轉(zhuǎn) NSString
// Start
NSDictionary *parametersDic = [NSDictionary dictionaryWithObjectsAndKeys:self.providerStr, KEY_LOGIN_PROVIDER,token, KEY_TOKEN,response, KEY_RESPONSE,nil];
NSData *jsonData = parametersDic == nil ? nil : [NSJSONSerialization dataWithJSONObject:parametersDic options:0 error:nil];
NSString *requestBody = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
將dictionary 轉(zhuǎn)化為 NSData芭梯, data 轉(zhuǎn)化為 string .
53.iOS7 中UIButton setImage 沒(méi)有起作用
如果在iOS7 中進(jìn)行設(shè)置image 沒(méi)有生效。
那么說(shuō)明UIButton的 enable 屬性沒(méi)有生效是NO的弄喘。 需要設(shè)置enable 為YES粥帚。
54.User-Agent 判斷設(shè)備UIWebView 會(huì)根據(jù)User-Agent 的值來(lái)判斷需要顯示哪個(gè)界面。如果需要設(shè)置為全局限次,那么直接在應(yīng)用啟動(dòng)的時(shí)候加載芒涡。
-(void)appendUserAgent
{
NSString *oldAgent = [self.WebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSString *newAgent = [oldAgent stringByAppendingString:@"iOS"];
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dic];
}
@“iOS" 為添加的自定義。
55.UIPasteboard 屏蔽paste 選項(xiàng)
當(dāng)UIpasteboard的string 設(shè)置為@“” 時(shí)卖漫,那么string會(huì)成為nil费尽。 就不會(huì)出現(xiàn)paste的選項(xiàng)。 ```
56.class_addMethod 使用
**當(dāng) ARC 環(huán)境下**
class_addMethod([self class], @selector(resolveThisMethodDynamically), (IMP) myMethodIMP, "v@:");
使用的時(shí)候@selector 需要使用super的class羊始,不然會(huì)報(bào)錯(cuò)旱幼。
**當(dāng)MRC環(huán)境下**
class_addMethod([EmptyClass class], @selector(sayHello2), (IMP)sayHello, "v@:");
可以任意定義。但是系統(tǒng)會(huì)出現(xiàn)警告突委,忽略警告就可以柏卤。```
57.AFNetworking 傳送 form-data
將JSON的數(shù)據(jù),轉(zhuǎn)化為NSData, 放入Request的body中匀油。 發(fā)送到服務(wù)器就是form-data格式缘缚。```
58.非空判斷注意
BOOL hasBccCode = YES;
if ( nil == bccCodeStr || [bccCodeStr isKindOfClass:[NSNull class]] || [bccCodeStr isEqualToString:@""])
{
hasBccCode = NO;
}
如果進(jìn)行非空判斷和類(lèi)型判斷時(shí),**需要新進(jìn)行類(lèi)型判斷敌蚜,再進(jìn)行非空判斷桥滨,不然會(huì)crash**。```
59.iOS 8.4 UIAlertView 鍵盤(pán)顯示問(wèn)題
可以在調(diào)用UIAlertView 之前進(jìn)行鍵盤(pán)是否已經(jīng)隱藏的判斷弛车。
@property (nonatomic, assign) BOOL hasShowdKeyboard;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissKeyboard) name:UIKeyboardDidHideNotification object:nil];
(void)showKeyboard
{
self.hasShowdKeyboard = YES;
}(void)dismissKeyboard
{
self.hasShowdKeyboard = NO;
}
while ( self.hasShowdKeyboard )
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
UIAlertView* alerview = [[UIAlertView alloc] initWithTitle:@"" message:@"取消修改?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: @"確定", nil];
[alerview show];
60.模擬器中文輸入法設(shè)置
模擬器默認(rèn)的配置種沒(méi)有“小地球”齐媒,只能輸入英文。加入中文方法如下:
選擇Settings--->General-->Keyboard-->International KeyBoards-->Add New Keyboard-->Chinese Simplified(PinYin) 即我們一般用的簡(jiǎn)體中文拼音輸入法纷跛,配置好后喻括,再輸入文字時(shí),點(diǎn)擊彈出鍵盤(pán)上的“小地球”就可以輸入中文了贫奠。如果不行唬血,可以長(zhǎng)按“小地球”選擇中文。
61.iPhone number pad
phone 的鍵盤(pán)類(lèi)型:
1.number pad 只能輸入數(shù)字叮阅,不能切換到其他輸入:

2.phone pad 類(lèi)型: 撥打電話的時(shí)候使用刁品,可以輸入數(shù)字和 + * # ```
62.UIView 自帶動(dòng)畫(huà)翻轉(zhuǎn)界面
- (IBAction)changeImages:(id)sender
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:_parentView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:_parentView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_parentView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_parentView cache:YES];
NSInteger purple = [[_parentView subviews] indexOfObject:self.image1];
NSInteger maroon = [[_parentView subviews] indexOfObject:self.image2];
[_parentView exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
63.KVO 監(jiān)聽(tīng)其他類(lèi)的變量
[[HXSLocationManager sharedManager] addObserver:self forKeyPath:@"currentBoxEntry.boxCodeStr" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionOld context:nil];
在實(shí)現(xiàn)的類(lèi)self中泣特,進(jìn)行[HXSLocationManager sharedManager]類(lèi)中的變量@“currentBoxEntry.boxCodeStr” 監(jiān)聽(tīng)浩姥。
64.ios9 crash animateWithDuration
在iOS9 中,如果進(jìn)行animateWithDuration 時(shí)状您,view被release 那么會(huì)引起crash勒叠。
[UIView animateWithDuration:0.25f animations:^{
self.frame = selfFrame;
} completion:^(BOOL finished) {
if (finished)
{
[super removeFromSuperview];
}
}];
會(huì)crash兜挨。
[UIView animateWithDuration:0.25f delay:0 usingSpringWithDamping:1.0 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.frame = selfFrame;
} completion:^(BOOL finished) {
[super removeFromSuperview];
}];
不會(huì)Crash。
65.對(duì)NSString進(jìn)行URL編碼轉(zhuǎn)換
iPTV項(xiàng)目中在刪除影片時(shí)眯分,URL中需傳送用戶(hù)名與影片ID兩個(gè)參數(shù)拌汇。當(dāng)用戶(hù)名中帶中文字符時(shí),刪除失敗弊决。
之前測(cè)試時(shí)噪舀,手機(jī)號(hào)綁定的用戶(hù)名是英文或數(shù)字。換了手機(jī)號(hào)測(cè)試時(shí)才發(fā)現(xiàn)這個(gè)問(wèn)題飘诗。
對(duì)于URL中有中文字符的情況与倡,需對(duì)URL進(jìn)行編碼轉(zhuǎn)換。
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
66.Xcode iOS加載圖片只能用PNG
雖然在Xcode可以看到j(luò)pg的圖片昆稿,但是在加載的時(shí)候會(huì)失敗纺座。錯(cuò)誤為 Could not load the "ReversalImage1" image referenced from a nib in the bun
**必須使用PNG的圖片。**
**如果需要使用JPG 需要添加后綴**
[UIImage imageNamed:@"myImage.jpg"];
67.保存全屏為image
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
for (UIWindow * window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, [window center].x, [window center].y);
CGContextConcatCTM(context, [window transform]);
CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y);
[[window layer] renderInContext:context];
CGContextRestoreGState(context);
}
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
68.判斷定位狀態(tài) locationServicesEnabled
這個(gè)[CLLocationManager locationServicesEnabled]檢測(cè)的是整個(gè)iOS系統(tǒng)的位置服務(wù)開(kāi)關(guān)溉潭,無(wú)法檢測(cè)當(dāng)前應(yīng)用是否被關(guān)閉净响。
通過(guò):
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status)
{
[self locationManager:self.locationManager didUpdateLocations:nil];
}
else
{
// the user has closed this function
[self.locationManager startUpdatingLocation];
}
**CLAuthorizationStatus**來(lái)判斷是否可以訪問(wèn)GPS
69.微信分享的時(shí)候注意大小
text 的大小必須 大于0 小于 10k
image 必須 小于 64k
url 必須 大于 0k```
70.圖片緩存的清空
一般使用SDWebImage 進(jìn)行圖片的顯示和緩存,一般緩存的內(nèi)容比較多了就需要進(jìn)行清空緩存
清除SDWebImage的內(nèi)存和硬盤(pán)時(shí)喳瓣,可以同時(shí)清除session 和 cookie的緩存馋贤。
// 清理內(nèi)存
[[SDImageCache sharedImageCache] clearMemory];
// 清理webview 緩存
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies])
{
[storage deleteCookie:cookie];
}
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
[config.URLCache removeAllCachedResponses];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// 清理硬盤(pán)
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[self.tableView reloadData];
}];
71.TableView Header View 跟隨Tableview 滾動(dòng)
當(dāng)tableview的類(lèi)型為 plain的時(shí)候,header View 就會(huì)停留在最上面畏陕。
當(dāng)類(lèi)型為 group的時(shí)候掸掸,header view 就會(huì)跟隨tableview 一起滾動(dòng)了。
72.TabBar的title 設(shè)置
在xib 或 storyboard 中可以進(jìn)行tabBar的設(shè)置:

其中badge 是自帶的在圖標(biāo)上添加一個(gè)角標(biāo)蹭秋。
- self.navigationItem.title 設(shè)置navigation的title 需要用這個(gè)進(jìn)行設(shè)置扰付。
- self.title 在tab bar的主VC 中,進(jìn)行設(shè)置self.title 會(huì)導(dǎo)致navigation 的title 和 tab bar的title一起被修改仁讨。
73.UITabBar,移除頂部的陰影
添加這兩行代碼:
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
頂部的陰影是在UIWindow上的羽莺,所以不能簡(jiǎn)單的設(shè)置就去除。```
74.當(dāng)一行中洞豁,多個(gè)UIKit 都是動(dòng)態(tài)的寬度設(shè)置:```

設(shè)置horizontal的值盐固,表示出現(xiàn)內(nèi)容很長(zhǎng)的時(shí)候,優(yōu)先壓縮這個(gè)UIKit丈挟。```
75.JSON的“<null>” 轉(zhuǎn)換為nil
//使用AFNetworking 時(shí)刁卜, 使用
AFJSONResponseSerializer *response = [[AFJSONResponseSerializer alloc] init];
response.removesKeysWithNullValues = YES;
_sharedClient.responseSerializer = response;
這個(gè)參數(shù) removesKeysWithNullValues 可以將null的值刪除,那么就Value為nil了
76.iOS 隨機(jī)顏色
view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];```
77.獲取時(shí)間戳
-(NSString *)created_at{
// Mon May 09 15:21:58 +0800 2016
//獲取微博發(fā)送時(shí)間
//把獲得的字符串時(shí)間 轉(zhuǎn)成 時(shí)間戳
//EEE(星期) MMM(月份)dd(天) HH小時(shí) mm分鐘 ss秒 Z時(shí)區(qū) yyyy年
NSDateFormatter *format = [[NSDateFormatter alloc]init];
format.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
//設(shè)置地區(qū)
format.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];
//微博發(fā)送時(shí)間
NSDate *weiboDate = [format dateFromString:<"要展示的字符串">];
//獲取當(dāng)前時(shí)間
NSDate *nowDate = [NSDate new];
long nowTime = [nowDate timeIntervalSince1970];
long weiboTime = [weiboDate timeIntervalSince1970];
//微博時(shí)間和當(dāng)前時(shí)間的時(shí)間差
long time = nowTime-weiboTime;
if (time<60) {//一分鐘內(nèi) 顯示剛剛
return @"剛剛";
}else if (time>60&&time<=3600){
return [NSString stringWithFormat:@"%d分鐘前",(int)time/60];
}else if (time>3600&&time<3600*24){
return [NSString stringWithFormat:@"%d小時(shí)前",(int)time/3600];
}else{//直接顯示日期
format.dateFormat = @"MM月dd日";
return [format stringFromDate:weiboDate];
}
}
```swift
78.NSString的一些特殊情況
//__autoreleasing 對(duì)象設(shè)置為這樣曙咽,要等到離自己最近的釋放池銷(xiāo)毀時(shí)才release
//__unsafe__unretained不安全不釋放蛔趴,為了兼容過(guò)去而存在,跟__weak很像,但是這個(gè)對(duì)象被銷(xiāo)毀后還在例朱,不像__weak那樣設(shè)置為nil
//__weak 一創(chuàng)建完孝情,要是沒(méi)有引用鱼蝉,馬上釋放,將對(duì)象置nil
//
__weak NSMutableString *str = [NSMutableString stringWithFormat:@"%@",@"xiaobai"];
//__weak 的話但是是alloc的對(duì)象箫荡,要交給autorelease管理
//arc下,不要release 和 autorelease因?yàn)?
79.設(shè)置UITabBarItem背景圖片
if(iOS7)
{
item = [iteminitWithTitle:title[i]image:[unSelectImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]selectedImage:[selectImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}
else
{
itemsetFinishedSelectedImage:selectImagewithFinishedUnselectedImage:unSelectImage];
item.title= title[i];
}
80.app跳轉(zhuǎn)到safari
NSURL* url = [NSURL URLWithString:urlStr];
[[UIApplication sharedApplication] openURL:url];
81.每個(gè)cell的高度,(使用autolayout可以實(shí)現(xiàn)自動(dòng)算高)
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//讓tableview自動(dòng)根據(jù)cell中的子視圖的約束,來(lái)計(jì)算自己的高度
return UITableViewAutomaticDimension;
}
82.解決編碼問(wèn)題
中文應(yīng)用都要遇到一個(gè)很頭疼的問(wèn)題:文字編碼魁亦,漢字的 GBK 和 國(guó)際通用的 UTF-8 的互相轉(zhuǎn)化稍一不慎,就會(huì)滿(mǎn)屏亂碼羔挡。下面介紹 UTF-8 和 GBK 的 NSString 相互轉(zhuǎn)化的方法!
從 GBK 轉(zhuǎn)到 UTF-8:
用 NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000) 洁奈,然后就可以用initWithData:encoding來(lái)實(shí)現(xiàn)。
從 UTF-8 轉(zhuǎn)到 GBK:
CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)绞灼,得到的enc卻是kCFStringEncodingInvalidId睬魂。
沒(méi)關(guān)系,試試 NSData *data=[nsstring dataUsingEncoding:-2147482063];
注意:必須使用kCFStringEncodingGB_18030_2000這個(gè)字符集镀赌,那個(gè)kCFStringEncodingGB_2312_80試了也不行氯哮。
下圖為證~!??
83.電池條的顏色
//方式一:
//新的電池條 風(fēng)格調(diào)整: 在需要變化電池條樣式的vc中, 重寫(xiě)下方方法即可
//新的方式: 當(dāng)前電池條的顏色 基于當(dāng)前控制器的設(shè)置.
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;//白
}
//方式二:
//舊的方式: 電池條的顏色與VC無(wú)關(guān). 這要修改plist文件, 把View controller-based status bar appearance屬性設(shè)置為NO
- (void)viewDidLoad {
[super viewDidLoad];
//設(shè)置整個(gè)應(yīng)用程序中所有頁(yè)面的電池條顏色
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
//還需要再info.plist中設(shè)置
84.xcode統(tǒng)計(jì)代碼量方法:
1.打開(kāi)終端,用cd命令 定位到工程所在的目錄商佛,然后調(diào)用以下命名即可把每個(gè)源代碼文件行數(shù)及總數(shù)統(tǒng)計(jì)出來(lái):
find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.h" -or -name "*.rss" ")" -print | xargs wc -l
85:iOS適配 之 關(guān)于info.plist 第三方登錄 添加URL Schemes白名單
近期蘋(píng)果公司iOS 9系統(tǒng)策略更新喉钢,限制了http協(xié)議的訪問(wèn),此外應(yīng)用需要在“Info.plist”中將要使用的URL Schemes列為白名單良姆,才可正常檢查其他應(yīng)用是否安裝肠虽。
受此影響,當(dāng)你的應(yīng)用在iOS 9中需要使用 QQ/QQ空間/支付寶/微信SDK 的相關(guān)能力(分享玛追、收藏税课、支付、登錄等)時(shí)痊剖,需要在“Info.plist”里增加如下代碼:
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 微信 URL Scheme 白名單-->
<string>wechat</string>
<string>weixin</string>
<!-- 新浪微博 URL Scheme 白名單-->
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
<!-- QQ韩玩、Qzone URL Scheme 白名單-->
<string>mqqapi</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqconnect</string>
<string>mqqopensdkdataline</string>
<string>mqqopensdkgrouptribeshare</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkapi</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqzoneopensdk</string>
<string>wtloginmqq</string>
<string>wtloginmqq2</string>
<string>mqqwpa</string>
<string>mqzone</string>
<string>mqzonev2</string>
<string>mqzoneshare</string>
<string>wtloginqzone</string>
<string>mqzonewx</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdk</string>
<!-- 支付寶 URL Scheme 白名單-->
<string>alipay</string>
<string>alipayshare</string>
</array>
具體操作步驟:
右鍵 info.plist /Open as/Source Code 將上面的代碼粘貼上去即可!
86.最近經(jīng)常看到有人在群里問(wèn)關(guān)于導(dǎo)航條透明的陆馁,廢話不多說(shuō)找颓,直接上代碼:
在ViewDidLoad方法里加上這三行代碼:
self.navigationController.navigationBar.translucent = YES;
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
在viewWillDisappear方法里加上這三行代碼:
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
self.navigationController.navigationBar.translucent分別表示開(kāi)啟、關(guān)閉導(dǎo)航條透明度
self.navigationController.navigationBar setBackgroundImage分別表示給導(dǎo)航條背景設(shè)置成空?qǐng)D片和恢復(fù)默認(rèn)
[self.navigationController.navigationBar setShadowImage給賦值空的UIImage對(duì)象的目的是為了去除導(dǎo)航條透明時(shí)下面的黑線叮贩,當(dāng)然賦值nil也是恢復(fù)默認(rèn)咯
在這里有一點(diǎn)需要說(shuō)明击狮,如果沒(méi)有禁用導(dǎo)航控制器的右滑pop手勢(shì)的話,在viewWillDisappear里寫(xiě)那代碼可能會(huì)有問(wèn)題哦
導(dǎo)航側(cè)滑pop手勢(shì)沒(méi)有禁用的時(shí)候益老,右滑彪蓬、在上一個(gè)界面快完全顯示的時(shí)候,左滑回去捺萌,然后档冬。。。自己去試試吧捣郊,哈哈
87.所有屏幕尺寸的宏定義:
#define IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : 0)
#define IPHONE4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : 0)
#define IPHONE6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : 0)
#define IPHONE6PLUS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : 0)