- 1、iOS子線程更新UI到主線程的三種方法
- 2、給self.view畫一個(gè)類似self.layer.border的虛線邊框
- 3笑窜、iOS畫小于1px的細(xì)線
- 4、iOS 設(shè)置行距蹭沛,并且計(jì)算有行距的文本高度
- 5臂寝、iOS NSData 轉(zhuǎn) Byte
- 6、PCH 絕對(duì)路徑格式與相對(duì)路徑
- 7摊灭、mac系統(tǒng)如何顯示或者隱藏隱形的文件夾
- 8咆贬、Byte、char帚呼、NSData掏缎、NSString 相互轉(zhuǎn)換
- 9、NSMutableData 的拼接煤杀、刪除眷蜈、插入
1、iOS子線程更新UI到主線程的三種方法
// 1.NSThread
[self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];
- (void)updateUI {
// UI更新代碼
self.alert.text = @"Thanks!";
}
// 2.NSOperationQueue
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// UI更新代碼 self.alert.text = @"Thanks!";
}];
// 3.GCD
dispatch_sync(dispatch_get_main_queue(), ^{
// UI更新代碼
self.alert.text = @"Thanks!";
});
2沈自、給self.view畫一個(gè)類似self.layer.border的虛線邊框
// 給self.view畫一個(gè)類似self.layer.border的虛線邊框
CAShapeLayer *border = [CAShapeLayer layer];
border.strokeColor = SLColorLine.CGColor;
border.fillColor = nil;
border.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
border.frame = self.bounds;
border.lineWidth = 1.f;
border.lineCap = @"square";
border.lineDashPattern = @[@4, @2];
[self.layer addSublayer:border];
3酌儒、iOS畫小于1px的細(xì)線
CALayer *layer = view.layer;
layer.borderColor = [UIColor whiteColor].CGColor;
layer.borderWidth = (1.0 / [UIScreen mainScreen].scale / 2);
4、iOS 設(shè)置行距酥泛,并且計(jì)算有行距的文本高度
[text addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, text.length)];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:5];//調(diào)整行間距
[text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
[self.topicDeatil.article.content boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16] ,NSParagraphStyleAttributeName : paragraphStyle} context:nil].size.height ;
5今豆、iOS NSData 轉(zhuǎn) Byte
在iOS中NSData轉(zhuǎn)Byte嫌拣,見到最多的NSData轉(zhuǎn)Byte的就是
NSString *string = @"123456";
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
Byte *testByte = (Byte *)[data bytes];
但是這種方法常常是不可行的柔袁,這時(shí)候就要換下面的方法了,
NSString *codeKey = @"123456";
NSData *codeKeyData = [codeKey dataUsingEncoding:NSUTF8StringEncoding];
Byte codeKeyByteAry[codeKeyData.length];
for (int i = 0 ; i < codeKeyData.length; i++) {
NSData *idata = [codeKeyData subdataWithRange:NSMakeRange(i, 1)];
codeKeyByteAry[i] =((Byte*)[idata bytes])[0];
}
6异逐、PCH 絕對(duì)路徑格式與相對(duì)路徑
PCH 絕對(duì)路徑格式:/Users/wan/Desktop/項(xiàng)目名/項(xiàng)目名/PrefixHeader.pch捶索,
轉(zhuǎn)化為相對(duì)路徑,如下格式$(SRCROOT)/項(xiàng)目名/PrefixHeader.pch
7灰瞻、mac系統(tǒng)如何顯示或者隱藏隱形的文件夾
一:顯示或者隱藏整個(gè)系統(tǒng)的隱形文件夾
顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false
二:顯示或者隱藏某個(gè)目錄下的隱形文件夾
顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles YES
隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles NO
8腥例、Byte、char酝润、NSData燎竖、NSString 相互轉(zhuǎn)換
//1.1、NSData --> Byte
NSString *testString = @"1234567890";
NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
Byte *DataByte = (Byte *)[testData bytes];
//1.2要销、Byte --> NSData
Byte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
NSData *Bytedata = [[NSData alloc] initWithBytes:byte length:24];
NSInteger byteLength2 = sizeof(byte2);
NSLog(@"字節(jié)長(zhǎng)度_byteLength2= %zd",byteLength2);//byteLength2= 24
NSLog(@"---<2.2>testByte: %s", DataByte);
NSLog(@"---<2.2>Bytedata: %@\n ", Bytedata);
//2.1构回、 NSString 轉(zhuǎn)化為 char*
NSString *strr = @"Test轉(zhuǎn)化123";
const char * charA = [strr UTF8String];
NSLog(@"charA = %s",charA);
//2.2、char* 轉(zhuǎn)化為 NSString
NSString *charToString = [NSString stringWithUTF8String:charA];
NSLog(@"charToString= %@ \n ",charToString);
//3.1疏咐、:NSString --> NSData
NSString * str1 = @"hello, world!";
NSData * data = [str1 dataUsingEncoding:NSUTF8StringEncoding];
//3.2纤掸、NSData --> NSString
NSString * dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"---<2.1>data.bytes: %s", data.bytes);
NSLog(@"---<2.1>dataString: %@\n ", dataString);
9、NSMutableData 的拼接浑塞、刪除借跪、插入
NSData *strData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *data = [NSMutableData data];
[data appendData:strData];
NSLog(@"data length= %ld",data.length);
// delete
[data replaceBytesInRange:NSMakeRange(0, 4) withBytes:NULL length:0];
NSLog(@"data length= %ld",data.length);
// insert
[data replaceBytesInRange:NSMakeRange(0, 0) withBytes:strData.bytes length:strData.length];
NSLog(@"data length= %ld",data.length);
}