第一.app如何添加AirDrop文件分享功能
蘋果在iOS 7 SDK中集成了UIActivityViewController類南用,可以讓你很簡單地就能把AirDrop功能整合進(jìn)app中!
MobileVLCKit 第三方 多格式支持 視頻播放!
第二.內(nèi)存泄露分析及解決
靜態(tài)分析內(nèi)存泄露 使用Xcode自帶的Analyze功能(Product-> Analyze)(Shift + Command + B)猪瞬,對代碼進(jìn)行靜態(tài)分析却舀,對于內(nèi)存泄露(Potential Memory Leak), 未使用局部變量(dead store)赌莺,邏輯錯誤(Logic Flaws)以及API使用問題(API-usage)等明確的展示出來。 靜態(tài)分析的內(nèi)存泄露情況比較簡單,開發(fā)者都能很快的解決。這里不做贅述鸠踪。
動態(tài)分析內(nèi)存泄露 使用Xcode自帶的Profile功能(Product-> Profile)(Command + i)彈出工具框丙者,選擇Leaks打開复斥,選擇運(yùn)行設(shè)備點(diǎn)左上角的Record錄制按鈕,項(xiàng)目就會在已選好的設(shè)備上運(yùn)行械媒,并開始錄制內(nèi)存檢測情況目锭。選Leaks查看泄露情況,在Leaks的詳細(xì)菜單Details選項(xiàng)里選調(diào)用樹Call Tree纷捞,可查看所有內(nèi)存泄露發(fā)生在哪些地方痢虹。再在右側(cè)的齒輪設(shè)置-Call Tree-勾選Hide System Libraries,則可直接看內(nèi)存泄露發(fā)生的函數(shù)名主儡、方法名奖唯。點(diǎn)擊函數(shù)名、方法名糜值,可直接跳到函數(shù)方法的細(xì)節(jié)丰捷,可以看到哪一句代碼出現(xiàn)了內(nèi)存泄露,以及泄露了多少內(nèi)存寂汇。
接下來就要回到Xcode病往,找到出現(xiàn)內(nèi)存泄露的函數(shù)方法,仔細(xì)分析如何出現(xiàn)的內(nèi)存泄露; 一般使用ARC骄瓣,按照上面一提到的內(nèi)存理解和編碼習(xí)慣是不會出現(xiàn)內(nèi)存泄露的停巷。但我們在開發(fā)過程中,經(jīng)常要使用第三方的一些類庫,特別是涉及到加密的類庫畔勤,用c或c++來編碼的加密解密方法蕾各,會出現(xiàn)內(nèi)存泄露。此時庆揪,我們要明白這些內(nèi)存分配示损,需要手動釋放。要一步一步看嚷硫,哪里分配了內(nèi)存检访,在使用完之后一定要記得釋放free它。
調(diào)試內(nèi)存泄露是一件讓人頭疼的事仔掸,如果你不想頭疼脆贵,請保持良好的編碼習(xí)慣。并在開發(fā)到一個階段時起暮,就要及時對應(yīng)用進(jìn)行內(nèi)存泄露分析卖氨。發(fā)現(xiàn)問題,及時修復(fù)负懦。
第三.block循環(huán)利用導(dǎo)致內(nèi)存泄漏
A *a = [[A alloc] init];
a.finishBlock = ^(NSDictionary paraments){ [a doSomething]; };
對于這種在block塊里引用對象a的情況筒捺,要在創(chuàng)建對象a時加修飾符block來防止循環(huán)引用。
block A *a = [[A alloc] init];
a.finishBlock = ^(NSDictionary paraments){ [a doSomething]; };
或 A __block a = [[A alloc] init]; a.finishBlock = ^(NSDictionary paraments){ [a doSomething]; };
或者纸厉,需要在block中調(diào)用用self的方法系吭、屬性、變量時颗品,可以這樣寫__weak typeof(self) weakSelf = self;在block中使用weakSelf肯尺。
__weak typeof(self) weakSelf = self; [b doSomethingWithFinishBlock:^{ weakSelf.text = @"內(nèi)存檢測"; [weakSelf doSomething]; }];
第四.label 的空格屬性和局部字段顏色
設(shè)置 label 的 autoresizingMask 為 NO ,可以使用空格間隔字符串!
[thirdLab setAttributedText:[self changeLabelWithText:@"點(diǎn)擊按鈕去注冊"]];
//獲取要調(diào)整顏色的文字位置,調(diào)整顏色 ,改變字體大小和字間距
-(NSMutableAttributedString*)changeLabelWithText:(NSString*)needText
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
[attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0,1)];
[attrString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:51/255.0 green:3/255.0 blue:4/255.0 alpha:1] range:NSMakeRange(0,1)];
[attrString addAttribute:NSKernAttributeName value:@1.0f range:NSMakeRange(0, needText.length)];
[attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(1,needText.length-1)];
[attrString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(1,needText.length-1)];
return attrString;
}
第五.過濾字符串
// 定義一個特殊字符的集合
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:
@"@/:;()¥「」"躯枢、[]{}#%-*+=_\\|~<>$€^?'@#$%^&*()_+'\""];
// 過濾字符串的特殊字符
NSString *newString = [trimString stringByTrimmingCharactersInSet:set];
第六.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);
}];
}
第七.label 行間距
-(void)test{
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:3];
//調(diào)整行間距
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [self.contentLabel.text length])];
self.contentLabel.attributedText = attributedString;
}
第八.設(shè)置滑動的時候隱藏 navigationbar
第1種:
navigationController.hidesBarsOnSwipe = Yes
第2種:
//1.當(dāng)我們的手離開屏幕時候隱藏
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if(velocity.y > 0)
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
} else {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
velocity.y這個量则吟,在上滑和下滑時,變化極谐濉(小數(shù))氓仲,但是因?yàn)榉较虿煌姓?fù)之分得糜,這就很好處理 了敬扛。
第九.屏幕截圖
// 1. 開啟一個與圖片相關(guān)的圖形上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0.0);
// 2. 獲取當(dāng)前圖形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 3. 獲取需要截取的view的layer
[self.view.layer renderInContext:ctx];
// 4. 從當(dāng)前上下文中獲取圖片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// 5. 關(guān)閉圖形上下文
UIGraphicsEndImageContext();
// 6. 把圖片保存到相冊
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
第十.導(dǎo)航欄、狀態(tài)欄和tabbar相關(guān)
1.導(dǎo)航欄
//隱藏導(dǎo)航欄上的返回字體
//Swift
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default)
//OC
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
//自定義導(dǎo)航欄的左右按鈕
UIButton *searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 90, 0, 30, 44)];
UIBarButtonItem *seaBtn = [[UIBarButtonItem alloc] initWithCustomView:searchBtn];
self.navigationItem.rightBarButtonItem = seaBtn;
2.狀態(tài)欄
//所有控制器狀態(tài)欄字體顏色
狀態(tài)欄字體顏色不同的辦法
1)掀亩、在info.plist中舔哪,將View controller-based status bar appearance設(shè)為NO.
2)、在app delegate中:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//單獨(dú)某個控制器字體顏色
3)槽棍、在個別狀態(tài)欄字體顏色不一樣的vc中
-(void)viewWillAppear:(BOOL)animated{
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
3.tabbar
+ (void)load
{
// 獲取當(dāng)前類的tabBarItem
UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
// 更改tabbar 選中字體顏色
UITabBar *tabbar = [UITabBar appearanceWhenContainedIn:self, nil];
tabbar.tintColor = [UIColor orangeColor];
// 設(shè)置所有item的選中時顏色
// 設(shè)置選中文字顏色
// 創(chuàng)建字典去描述文本
NSMutableDictionary *attSelect = [NSMutableDictionary dictionary];
// 文本顏色 -> 描述富文本屬性的key -> NSAttributedString.h
attSelect[NSForegroundColorAttributeName] = [UIColor orangeColor];
[item setTitleTextAttributes:attSelect forState:UIControlStateSelected];
// 通過normal狀態(tài)設(shè)置字體大小
// 字體大小 跟 normal
NSMutableDictionary *attrNormal = [NSMutableDictionary dictionary];
// 設(shè)置字體
attrNormal[NSFontAttributeName] = [UIFont systemFontOfSize:13];
[item setTitleTextAttributes:attrNormal forState:UIControlStateNormal];
// 文字偏移量
//[item setTitlePositionAdjustment:<#(UIOffset)#>];
// icon偏移量
// item.imageInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>);
}
第十一.去掉 tabbar 和 navgationbar 的黑線
//去掉tabBar頂部線條
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.tabBar setBackgroundImage:img];
[self.tabBar setShadowImage:img];
//[self.navigationController.navigationBar setBackgroundImage:img];
//self.navigationController.navigationBar.shadowImage = ima;
self.tabBar.backgroundColor = SLIVERYCOLOR;
第十二.判斷字符串中是否含有中文
-(BOOL)isChinese:(NSString *)str{
NSString *match=@"(^[\u4e00-\u9fa5]+$)";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
return [predicate evaluateWithObject:str];
}
第十三.解決父視圖和子視圖的手勢沖突
/** 解決手勢沖突 */
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isDescendantOfView:cicView]) {
return NO;
}
return YES;
}
第十四.NSDate與NSString的相互轉(zhuǎn)化
-(NSString *)dateToString:(NSDate *)date {
// 初始化時間格式控制器
NSDateFormatter *matter = [[NSDateFormatter alloc] init];
// 設(shè)置設(shè)計格式
[matter setDateFormat:@"yyyy-MM-dd hh:mm:ss zzz"];
// 進(jìn)行轉(zhuǎn)換
NSString *dateStr = [matter stringFromDate:date];
return dateStr;
}
-(NSDate *)stringToDate:(NSString *)dateStr {
// 初始化時間格式控制器
NSDateFormatter *matter = [[NSDateFormatter alloc] init];
// 設(shè)置設(shè)計格式
[matter setDateFormat:@"yyyy-MM-dd hh:mm:ss zzz"];
// 進(jìn)行轉(zhuǎn)換
NSDate *date = [matter dateFromString:dateStr];
return date;
}
第十五.Xcode 8 注釋設(shè)置
打開終端捉蚤,命令運(yùn)行: sudo /usr/libexec/xpccachectl
然后必須重啟電腦后生效
十六.刪除storyboard的方法
一般情況下抬驴,我們有時候不想用storyboard,但是直接刪除的話缆巧,Xcode就會報錯布持。那我今天就來講一下,正確刪除storyboard的方法陕悬。
第一题暖,直接將工程中的storyboard直接刪除掉,這樣你覺得就OK了捉超?你錯了胧卤,還是要有第二步的。
第二拼岳,找到plist文件枝誊,將plist文件中的Main storyboard file base name刪除掉,如圖所示
十七.ASCII 和 NSString 的相互轉(zhuǎn)換
// NSString to ASCII
NSString *string = @"A";
int asciiCode = [string characterAtIndex:0]; //65
//ASCII to NSString
int asciiCode = 65;
NSString *string =[NSString stringWithFormat:@"%c",asciiCode]; //A
十八.獲取當(dāng)前連接的wifi名稱
NSString *wifiName = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();
if (myArray != nil) {
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (myDict != nil) {
NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
wifiName = [dict valueForKey:@"SSID"];
}
}
NSLog(@"wifiName:%@", wifiName);
十九.蘋果自帶的下拉刷新方法
//設(shè)置下拉刷新 UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
NSDictionary dict = @{NSForegroundColorAttributeName:[UIColor redColor]};
NSAttributedString string = [[NSAttributedString alloc] initWithString:@"幫你署最新惜纸。叶撒。" attributes:dict];
refresh.attributedTitle = string;
[self.tableView addSubview:refresh];
二十.顯示和隱藏系統(tǒng)文件
顯示Mac隱藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
隱藏Mac隱藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false
二十一.跨控制器跳轉(zhuǎn)返回
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[@“你要返回的控制器類名” class]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
二十二. layer.cornerRadius 圓角流暢性的優(yōu)化
第一種:CornerRadius
loginBtn.layer.cornerRadius = 10;
loginBtn.layer.shouldRasterize = YES;
loginBtn.layer.rasterizationScale = [UIScreen mainScreen].scale;
第二種:UIBezierPath 和 CAShapeLayer
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_draw.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:_draw.bounds.size];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
// 設(shè)置大小
maskLayer.frame = _draw.bounds;
// 設(shè)置圖形樣子
maskLayer.path = maskPath.CGPath;
_draw.layer.mask = maskLayer;
第三種:設(shè)置上半部分圓角
_titleLabel.layer.masksToBounds = YES;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:_titleLabel.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){5.0f, 5.0f}].CGPath;
_titleLabel.layer.mask = maskLayer;
二十三.導(dǎo)航欄和下方視圖間隔距離消失 以及 導(dǎo)航欄和下方視圖不重疊
//不間隔
self.automaticallyAdjustsScrollViewInsets=YES;
//不重疊
self.edgesForExtendedLayout = UIRectEdgeNone
二十四.毛玻璃效果(ios8.0以后的版本)
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
visualEffectView.frame = CGRectMake(0, 0, 320*[FlexibleFrame ratio], 180*[FlexibleFrame ratio]);
visualEffectView.alpha = 1.0;
二十五.工作中常用的第三方
二十六.PCH文件中的小玩意
創(chuàng)建.pch文件時 , BuildSetting 中的 Prefix Header 中的路徑開頭可以寫 $(SRCROOT)/工程地址, 這樣寫的好處可以使你的挪動代碼不用手動更換路徑!
二十七.如何點(diǎn)擊谷歌地圖獲取所在位置經(jīng)緯度?
調(diào)用谷歌地圖 mapView:didTapAtCoordinate: 方法,即可獲得!
二十八.AppIcon 和 launch image 尺寸相關(guān)
** 二十九.iO中判斷兩個數(shù)組是否相同**
NSArray *array1 = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSArray *array2 = [NSArray arrayWithObjects:@"d", @"a", @"c", nil];
bool bol = false;
//創(chuàng)建倆新的數(shù)組
NSMutableArray *oldArr = [NSMutableArray arrayWithArray:array1];
NSMutableArray *newArr = [NSMutableArray arrayWithArray:array2];
//對數(shù)組1排序。
[oldArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
return obj1 > obj2;
}];
//對數(shù)組2排序耐版。
[newArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
return obj1 > obj2;
}];
if (newArr.count == oldArr.count) {
bol = true;
for (int16_t i = 0; i < oldArr.count; i++) {
id c1 = [oldArr objectAtIndex:i];
id newc = [newArr objectAtIndex:i];
if (![newc isEqualToString:c1]) {
bol = false;
break;
}
}
}
if (bol) {
NSLog(@" ------------- 兩個數(shù)組的內(nèi)容相同祠够!");
}
else {
NSLog(@"-=-------------兩個數(shù)組的內(nèi)容不相同!");
}
三十.屏幕渲染--顏色漸變
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)[UIColor whiteColor].CGColor,(__bridge id)[UIColor grayColor].CGColor,(__bridge id)[UIColor whiteColor].CGColor];
gradientLayer.locations = @[@0.2,@0.65,@0.75];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 2);
[self.view.layer addSublayer:gradientLayer];
三十一.快速求和粪牲,最大值古瓤,最小值,平均值
NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil];
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
三十二.對比時間差
-(int)max:(NSDate *)datatime
{
//創(chuàng)建日期格式化對象
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
NSDate * senddate=[NSDate date];
NSString * locationString=[dateFormatter stringFromDate:senddate];
NSDate *date=[dateFormatter dateFromString:locationString];
//取兩個日期對象的時間間隔:
//這里的NSTimeInterval 并不是對象虑瀑,是基本型湿滓,其實(shí)是double類型滴须,是由c定義的:typedef double NSTimeInterval;
NSTimeInterval time=[date timeIntervalSinceDate:datatime];
int days=((int)time)/(3600*24);
return days;
}
三十三.請求定位權(quán)限以及定位屬性
_在地圖頁面放入下面代碼:_
//定位管理器
_locationManager=[[CLLocationManager alloc]init];
//如果沒有授權(quán)則請求用戶授權(quán)
if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
[_locationManager requestWhenInUseAuthorization];
}else if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
//設(shè)置代理
_locationManager.delegate=self;
//設(shè)置定位精度
_locationManager.desiredAccuracy=kCLLocationAccuracyBest;
//定位頻率,每隔多少米定位一次
CLLocationDistance distance=10.0;//十米定位一次
_locationManager.distanceFilter=distance;
//啟動跟蹤定位
[_locationManager startUpdatingLocation];
}
三十四.將幾張圖片合成為一張
- (UIImage *)composeWithHeader:(UIImage *)header content:(UIImage *)content footer:(UIImage *)footer{
CGSize size = CGSizeMake(content.size.width, header.size.height +content.size.height +footer.size.height);
UIGraphicsBeginImageContext(size);
[header drawInRect:CGRectMake(0,
0,
header.size.width,
header.size.height)];
[content drawInRect:CGRectMake(0,
header.size.height,
content.size.width,
content.size.height)];
[footer drawInRect:CGRectMake(0,
header.size.height+content.size.height,
footer.size.width,
footer.size.height)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
三十五.按鈕的選擇狀態(tài)及與BarButton的結(jié)合使用
self.barRightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.barRightBtn.frame = CGRectMake(WIDTH-20, 30, 80, 30);
[self.barRightBtn setTitle:@"停止掃描" forState:UIControlStateNormal];
[self.barRightBtn setTitle:@"開始掃描" forState:UIControlStateSelected];
[self.barRightBtn setTitleColor:BLUECOLOR forState:UIControlStateNormal];
self.barRightBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[[self.barRightBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
self.barRightBtn.selected = !self.barRightBtn.selected;
if (self.barRightBtn.selected) {
[self endScanIbeacon];
}else{
[self startScanIbecan];
}
}];
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:self.barRightBtn];
self.navigationItem.rightBarButtonItem = barBtn;
三十六.自定義ttf字體
1.將xx.ttf字體庫加入工程里;
2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application舌狗,加上字體庫的名稱;
3.引用字體庫的名稱,設(shè)置字體: [UIFontfontWithName:@"fontname" size:24];
4.如果不知道字體名稱扔水,可以遍歷字體進(jìn)行查詢;或者選中項(xiàng)目中的導(dǎo)入字體痛侍,然后showInFinder,雙擊打開查看最上面的字體介紹:
for(NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@"family:'%@'",fontfamilyname);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"-------------");
}
三十七.導(dǎo)航欄字體顏色改變
有時候想改變某個控制器中狀態(tài)欄的字體顏色,單純的在控制器添加 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent],發(fā)現(xiàn)添加后無改變!這時候就需要設(shè)置另外一個屬性!
1.在 info.plist 中,將 View controller-based status bar appearance 設(shè)為 NO;
2. 在對應(yīng)控制器添加[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
三十八.類似于 modal 效果的彈出視圖
//初始化
PopView *pop = [[PopView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT-150)];
pop.bgImaView.image = [UIImage imageNamed:[NSString stringWithFormat:@"backgaund_%ld",(long)index]];
[self.view addSubview:pop];
//點(diǎn)擊后frame改變,動畫展示上滑 (類似于 btn 點(diǎn)擊事件)
[UIView animateWithDuration:0.5 animations:^{
pop.frame = CGRectMake(0, 150, WIDTH, HEIGHT-150);
}];
//在點(diǎn)擊改變frame,動畫展示下滑
[UIView animateWithDuration:0.5 animations:^{
pop.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT-150);
}];
三十九.masonry 動畫效果有時候不實(shí)現(xiàn)需要添加此方法
四十.設(shè)置手機(jī)聲音震動
#import <AudioToolbox/AudioToolbox.h>
#import <UIKit/UIKit.h>
- (void)vibrate {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
**四十一.判斷一個點(diǎn)是否在一個區(qū)域魔市,判斷一個區(qū)域是否在一個區(qū)域 **
1.CGRect 和 CGPoint 對比 (判斷一個點(diǎn)是否在一個區(qū)域)
BOOL a = CGRectContainsPoint(_view.frame, point)
2.CGRect 和 CGRect 對比 (判斷一個區(qū)域是否在一個區(qū)域)
BOOL b = CGRectContainsRect(_view.frame,_btn.frame)
3. CGPoint 和 CGPoint 對比 (判斷兩個點(diǎn)是否相同)
BOOL c = CGPointEqualToPoint(point1, point2);
四十二,圖片的簡單壓縮
1. //背景視圖 (此種壓縮有白邊出現(xiàn))
UIImageView *bgIma = [[UIImageView alloc] initWithFrame:BOUNDS];
NSString *bgFile = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath,@"zsBg.png"]; //圖片緩存處理
UIImage *image = [[UIImage alloc] initWithContentsOfFile:bgFile];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
bgIma.image = [UIImage imageWithData:data];
[self addSubview:bgIma];
2.封裝方法
- (UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
// Tell the old image to draw in this new context, with the desired
// new size
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}
((UIImageView *)view).image = [self imageWithImage:[UIImage imageNamed:self.notiArr[index]] scaledToSize:CGSizeMake(WIDTH-20, HEIGHT-64-10-180)] ;
** 四十三.橫豎屏詳細(xì)相關(guān)(全局豎屏,特殊控制器橫屏)**
1.點(diǎn)項(xiàng)目 - Targets - General - Deployment Info 滞项,如圖
2.在 appdelegate 頭文件中添加屬性
/// 判斷是否橫豎屏
@property (nonatomic,assign)BOOL allowRotation;
3.在 appdelegate 實(shí)現(xiàn)文件中實(shí)現(xiàn)方法
/* 橫豎屏 */
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.allowRotation) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
4.在需要橫屏的文件中筹麸,導(dǎo)入頭文件 #import "AppDelegate.h" ,添加如此代碼
/// 橫豎屏相關(guān)
AppDelegate *app =(AppDelegate *)[[UIApplication sharedApplication] delegate];
app.allowRotation = YES;
四十四.后臺無線定位
四十五.使用Xcode查找項(xiàng)目中的中文字符串,以方便實(shí)現(xiàn)國際化的需求
1.打開”Find Navigator” (小放大鏡模樣 --- > ??)
2.切換搜索模式到 “Find > Regular Expression”
3.輸入@"[^"]*[\u4E00-\u9FA5]+[^"\n]*?" (swift請去掉”@” 輸入@"[^"]*[\u4E00-\u9FA5]+[^"\n]*?" 就好了)
四十六.判斷 iOS 系統(tǒng)版本
_判斷 iOS 系統(tǒng)版本大于10_
#define IOS_VERSION_10 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_x_Max)?(YES):(NO)
_判斷 iOS系統(tǒng)具體版本_
1.預(yù)編譯文件(.pch文件)定義
#define iPHONEType struct utsname systemInfo;uname(&systemInfo);
引用
iPHONEType
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
2.[UIDevice currentDevice].systemVersion.floatValue ,例如:
if ([UIDevice currentDevice].systemVersion.floatValue < 7.0f) {
Method newMethod = class_getInstanceMethod(self, @selector(compatible_setSeparatorInset:));
// 增加Dummy方法
class_addMethod(
self,
@selector(setSeparatorInset:),
method_getImplementation(newMethod),
method_getTypeEncoding(newMethod));
}
四十七.判斷 label 文字行數(shù)
- (NSArray *)getLinesArrayOfStringInLabel:(UILabel *)label{
NSString *text = [label text];
UIFont *font = [label font];
CGRect rect = [label frame];
CTFontRef myFont = CTFontCreateWithName(( CFStringRef)([font fontName]), [font pointSize], NULL);
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
[attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)myFont range:NSMakeRange(0, attStr.length)];
CFRelease(myFont);
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(( CFAttributedStringRef)attStr);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectMake(0,0,rect.size.width,100000));
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
NSArray *lines = ( NSArray *)CTFrameGetLines(frame);
NSMutableArray *linesArray = [[NSMutableArray alloc]init];
for (id line in lines) {
CTLineRef lineRef = (__bridge CTLineRef )line;
CFRange lineRange = CTLineGetStringRange(lineRef);
NSRange range = NSMakeRange(lineRange.location, lineRange.length);
NSString *lineString = [text substringWithRange:range];
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithFloat:0.0]));
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithInt:0.0]));
//NSLog(@"''''''''''''''''''%@",lineString);
[linesArray addObject:lineString];
}
CGPathRelease(path);
CFRelease( frame );
CFRelease(frameSetter);
return (NSArray *)linesArray;
}
四十八.性能優(yōu)化的小玩意 (Debug模式)
1. Product→Scheme→Edit Scheme 中 Run - Arguments - Environment Variables 設(shè)置Name為OS_ACTIVITY_MODE,Value為disable; //去除Xcode無效數(shù)據(jù),也就是 去除 所有 NSLog 打印信息
2.寫到 .PCH 文件中 ,用來代替工程中的 NSLog 打印
#ifdef DEBUG
#define SLog(format, ...) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )
#else
#define SLog(format, ...)
#endif
3. release模式下 系統(tǒng)自動注釋slog , 以便于優(yōu)化性能
四十九.篩選字符串(去除空格 換行符 回車符 首尾兩端)
- (NSString *)returnCustomString:(NSString *)string
{
[[[[[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByReplacingOccurrencesOfString:@"/r" withString:@""] stringByReplacingOccurrencesOfString:@"/n" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""] stringByReplacingOccurrencesOfString:@"/tab" withString:@""];
return string;
}
五十.數(shù)組和字典打印輸出中文(新建一個分類将宪,粘貼如下代碼)
@implementation NSDictionary (LOG)
- (NSString *)descriptionWithLocale:(id)locale
{
// 1.定義一個可變的字符串, 保存拼接結(jié)果
NSMutableString *strM = [NSMutableString string];
[strM appendString:@"{\n"];
// 2.迭代字典中所有的key/value, 將這些值拼接到字符串中
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[strM appendFormat:@"\t%@ = %@,\n", key, obj];
}];
[strM appendString:@"}"];
// 刪除最后一個逗號
if (self.allKeys.count > 0) {
NSRange range = [strM rangeOfString:@"," options:NSBackwardsSearch];
[strM deleteCharactersInRange:range];
}
// 3.返回拼接好的字符串
return strM;
}
@end
@implementation NSArray (LOG)
- (NSString *)descriptionWithLocale:(id)locale
{
// 1.定義一個可變的字符串, 保存拼接結(jié)果
NSMutableString *strM = [NSMutableString string];
[strM appendString:@"(\n"];
// 2.迭代字典中所有的key/value, 將這些值拼接到字符串中
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[strM appendFormat:@"\t%@,\n", obj];
}];
[strM appendString:@")\n"];
// 刪除最后一個逗號
if (self.count > 0) {
NSRange range = [strM rangeOfString:@"," options:NSBackwardsSearch];
[strM deleteCharactersInRange:range];
}
// 3.返回拼接好的字符串
return strM;
}
@end
五十一 . 十六進(jìn)制轉(zhuǎn)十進(jìn)制
- (NSString *)turn16to10:(NSString *)str {
if (str.length>10) {
str =[str substringFromIndex:str.length-10];
}
NSLog(@"字符=%@", str);
unsigned long long result = 0;
NSScanner *scanner = [NSScanner scannerWithString:str];
[scanner scanHexLongLong:&result];
NSString *tempInt =[NSString stringWithFormat:@"%llu", result];
if (tempInt.length>7) {
tempInt =[tempInt substringFromIndex:tempInt.length-7];
}
NSLog(@"數(shù)字=%@", tempInt);
return tempInt;
}
五十二.禁止蘋果自帶的側(cè)滑返回功能
第一種方法:
1.在需要禁止的控制器里面關(guān)閉側(cè)滑返回
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// 禁用返回手勢
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
2.如果只是單個頁面關(guān)閉绘闷,其他頁面可以側(cè)滑返回
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// 開啟返回手勢
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
第二種方法:
-(void)popGestureChange:(UIViewController *)vc enable:(BOOL)enable{
if ([vc.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//遍歷所有的手勢
for (UIGestureRecognizer *popGesture in vc.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {
popGesture.enabled = enable;
}
}
}
這個函數(shù)的使用可以在viewDidAppear調(diào)用橡庞,調(diào)用完之后記得在viewDidDisappear恢復(fù)原先的設(shè)置
五十三、合并framework
1.常規(guī)的需要合并 真機(jī)版framework 和模擬器版framework 印蔗,需要用到 lipo指令:lipo -create 真機(jī)版本路徑 模擬器版本路徑 -output 合并后的文件路徑 (注:空格不能省去)扒最!示例:
路徑1:/Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework
路徑2:/Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework
合并后的路徑及名稱:/Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/IJKMediaFramework
lipo -create /Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework /Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output /Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/IJKMediaFramework
2.報錯及注意點(diǎn)
1)指令之間的空格不能省去
2)報錯:fatal error: can't map input file
原因是因?yàn)?framework 路徑格式輸入錯誤,需要將 xxxFramework.framework 改成 xxxFramework.framework/xxxFramework
3)報錯:can't move temporary file
原因是因?yàn)?合并后的 路徑格式輸入錯誤华嘹,需要在路徑后面加入合并后你起的文件名稱 吧趣,/Users/Zhuge_Su/Desktop 改成 /Users/Zhuge_Su/Desktop/xxx.framework (xxx需要自己自定義)
五十四、更改 textfield 占位符 相關(guān)
UIColor *color = [UIColor whiteColor];
_userName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用戶名" attributes:@{NSForegroundColorAttributeName: color}];
五十五耙厚、tableview 從第四行或者第五行顯示 解決方法
在動態(tài)布局tableview行高的時候强挫,會出現(xiàn)tableview cell 從第四行或者第五行開始加載,解決方案:昨個判斷 如果動態(tài)行高大于0 顯示動態(tài)行高薛躬;如果動態(tài)行高等于0 纠拔,默認(rèn)返回一個 1或者 2值 ,舉例:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.totalCellHeight > 0) {
return self.totalCellHeight;
} else{
return 1;
}
return 0;
}
五十四.IPV6環(huán)境搭建
Enter your link description here:
五十五.加急審核鏈接
[ 鏈接 ](https://developer.apple.com/appstore/contact/appreviewteam/index.html)
五十六.上架審核的小注意點(diǎn)
1.檢查全局?jǐn)帱c(diǎn)是否都清除完畢;
2.檢查 EditScheme 是否都是release狀態(tài);
3.檢查所有數(shù)據(jù)是否包含 測試,demo 等中英文字樣;
4.檢查 后臺模式,去除掉不需要使用的后臺模式,尤其是定位相關(guān);相關(guān)文字描述要描述清楚;
5.為以防萬一,未開發(fā)的項(xiàng)目還是隱藏的好(看個人人品);
6.產(chǎn)品流程上,可點(diǎn)擊和不可點(diǎn)擊狀態(tài)要有不同顯示或者提示;
五十七.app在app store 上的地址
http://itunes.apple.com/cn/app/idXXXXXXXXXX?mt=8 (XXXXXXXXXX 是你app 在itunes connect上創(chuàng)建的app id)
itms-apps://itunes.apple.com/app/id1144099528
五十八泛豪、Xcode斷點(diǎn)失效解決方法
1.首先點(diǎn)擊菜單product->Debug workflow取消選中show Disassembly when debug 是否勾選,如果勾選點(diǎn)擊取消
2. Build Setting 中 Generate Debug Symbols 設(shè)置為 Yes
3.Build Setting中將`Enable Clang Module Debugging`設(shè)置為`NO`即可",
五十九稠诲、更改項(xiàng)目名字
六十、下載Xcode中的版本
六十一诡曙、iPhone X tabbar重影
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
for (UIView *child in self.tabBarController.tabBar.subviews) {
if ([child isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[child removeFromSuperview];
}
}
}
六十二臀叙、轉(zhuǎn)讓app
六十三、蘋果開發(fā)者相關(guān)
電話: 4006701855
網(wǎng)址:https://developer.apple.com
3.2.1審核相關(guān)網(wǎng)址:https://tieba.baidu.com/p/5659292532?red_tag=2857790889
https://www.cnblogs.com/zk1947/p/8425506.html
六十四价卤、iTerm 自動補(bǔ)全相關(guān)
打開終端劝萤,輸入 :
nano .inputrc
在文件里面寫上:
set completion-ignore-case on
set show-all-if-ambiguous on
TAB: menu-complete
ctrl + o ,回車,重啟終端慎璧,自動補(bǔ)全按tap鍵就ok床嫌。
更改iterm2的顏色
傳送門
六十五、描述文件相關(guān)
1.查看描述文件的位置
所有的描述文件安裝后胸私,都保存在Provisioning Profiles目錄下厌处。完整路徑為:~/Library/MobileDevice/Provisioning Profiles
2.查看描述文件的內(nèi)容
在終端使用命令查看:/usr/bin/security cms -D -i 文件路徑
六十六、如何解決“app已損壞岁疼,打不開阔涉。你應(yīng)該將它移到廢紙簍。
命令行運(yùn)行:
修改系統(tǒng)配置:系統(tǒng)偏好設(shè)置… -> 安全性與隱私捷绒。修改為任何來源
如果沒有這個選項(xiàng)的話 ,打開終端瑰排,執(zhí)行
sudo spctl --master-disable
sudo spctl --master-disable Rference
六十七、新建Xcode指定默認(rèn)類名前綴
六十八暖侨、測試iOS版的App注意事項(xiàng)
1椭住、app使用過程中,接聽電話字逗,可以測試不同的通話時間的長短京郑,對于通話結(jié)束后显押,原先打開的app的響應(yīng),比如是否停留在原先界面傻挂,繼續(xù)操作時的相應(yīng)速度等乘碑。
2、app使用過程中金拒,有推送消息時兽肤,對app的使用影響。
3绪抛、設(shè)備在充電時资铡,app的響應(yīng)以及操作流暢度。
4幢码、設(shè)備在不同電量時(低于10%笤休,50%95%),app的響應(yīng)以及操作流暢度
5症副、意外斷電時店雅,app數(shù)據(jù)丟失情況
6、網(wǎng)絡(luò)環(huán)境變化時贞铣,app的應(yīng)對情況如何:是否有是當(dāng)提示闹啦?從有網(wǎng)絡(luò)環(huán)境到無網(wǎng)絡(luò)環(huán)境時,app的反饋如何辕坝?從無網(wǎng)絡(luò)環(huán)境回到有網(wǎng)絡(luò)環(huán)境時窍奋,是否能自動加載數(shù)據(jù),多久才能開始加載數(shù)據(jù)
7酱畅、多點(diǎn)觸摸的情況
8琳袄、跟其他app之間互相切換時的響應(yīng)
9、進(jìn)程關(guān)閉再重新打開的反饋
10纺酸、iOS系統(tǒng)語言環(huán)境變化時
六十九窖逗、QQ ID 轉(zhuǎn) 十六進(jìn)制
echo 'ibase=10;obase=16;101553465'|bc
七十、查看cocoapods版本和.a版本
pod search GoogleWebRTC (查看cocoapods下三方版本)
lipo -info XXX.a (cd到.a目錄下吁峻,輸出指令)
七十一滑负、查看cocoapods版本和.a版本
self.areaIcon.image = [[UIImage imageNamed:@"ico_title_city.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.areaIcon.tintColor = [UIColor whiteColor];
七十二、根據(jù)滾動距離調(diào)整導(dǎo)航視圖透明度
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat y = scrollView.contentOffset.y;
self.navBarContainer.alpha = y/(546 * (kDeviceWidth / 750.0) - MSUNavHeight);
CGFloat alpha = self.navBarContainer.alpha * 3;
self.leftButton.alpha = 1 - alpha;
}
七十三用含、當(dāng)前頁面設(shè)置后切換整個App設(shè)置
1.不含子視圖的切換 (項(xiàng)目視圖層級比較多,所以多了一層)
MSUMainTabbarController *tab = [[MSUMainTabbarController alloc] init];
tab.selectedIndex = 3;
MSUMainNavigationController *mainNav = (MSUMainNavigationController *)tab.selectedViewController;
TUNewPersonController *new = (TUNewPersonController *)mainNav.visibleViewController;
new.selectedIndex = index;
///解決動畫bug
dispatch_async(dispatch_get_main_queue(), ^{
[[[UIApplication sharedApplication] delegate] window].rootViewController = tab;
//一些UI提示帮匾,可以提供更友好的用戶交互(也可以刪掉)
[SVProgressHUD showWithStatus:@"正在切換"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
});
2.包含子視圖的切換(項(xiàng)目視圖層級比較多啄骇,所以多了一層)
MSUMainTabbarController *tab = [[MSUMainTabbarController alloc] init];
tab.selectedIndex = 3;
MSUMainNavigationController *mainNav = (MSUMainNavigationController *)tab.selectedViewController;
TUNewPersonController *new = (TUNewPersonController *)mainNav.visibleViewController;
new.selectedIndex = 0;
MSUMainNavigationController *newNav = (MSUMainNavigationController *)new.selectedViewController;
TUPersonSettingController *set = [[TUPersonSettingController alloc] init];
TULampSetController *lamp = [[TULampSetController alloc] init];
newNav.viewControllers = @[set,lamp];
///解決動畫bug
dispatch_async(dispatch_get_main_queue(), ^{
g_window.rootViewController = tab;
[[NSNotificationCenter defaultCenter] postNotificationName:TUSettingChange object:nil];
//一些UI提示,可以提供更友好的用戶交互(也可以刪掉)
[SVProgressHUD showWithStatus:@"正在切換"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
});
七十四瘟斜、多Configuration配置環(huán)境
1.在Project - Info - Configuration 新增需要的configuration環(huán)境
2.在PODS - Info - Configuration 新增需要的configuration環(huán)境
3.pod install 后 缸夹,查看Project 和 PODS 里面的Build setting 對應(yīng)的Preproessor Macro 里面的鍵值對
4.使用
七十五痪寻、大文件下載 -- lfs
brew install git-lfs
git lfs install
七十六、xcode搜索<replace>漢字替換正則匹配
1.@".[\u4e00-\u9fa5]+."
2.:@"["]*[\u4E00-\u9FA5]+["\n]?"
3.@"[^"][\u4E00-\u9FA5]+[^"\n]?"
4.(@"[^"][\u4E00-\u9FA5]+[^"\n]*?")
LCLocalizedString(nil, $1)
七十七虽惭、查詢某個framework是否支持bitcode
otool -l framework二進(jìn)制文件地址 | grep __LLVM | wc -l
為0表示不支持
七十八橡类、label的展開和收起
/// 是否展示展開/收起
- (void)setupAddMoreBtn
{
BOOL isShowAll = self.model.isShowAll;
self.contentLabel.numberOfLines = isShowAll ? 0 : 2;
NSString *contentStr = self.model.content;
if ([LCPathTools checkIsJsonString:self.model.content]) {
LCCommunityContentModel *contentModel = [LCCommunityContentModel yy_modelWithJSON:self.model.content];
contentStr = contentModel.content;
}
NSMutableAttributedString *attStr = [self getFinalContentStrWithContent:contentStr];
YYTextLayout *layoutWidth = [YYTextLayout layoutWithContainerSize:CGSizeMake(LCDeviceWidth - LC_X(87), CGFLOAT_MAX) text:attStr.copy];
if (layoutWidth.rowCount > 2) {
NSString *str = isShowAll ? LCLocalizedString(@"App_domestic_2501", @"收起") : LCLocalizedString(@"App_domestic_3237", @"展開");
NSMutableAttributedString *showAtt = [self getFinalContentStrWithContent:[NSString stringWithFormat:@"... %@", str]];
if (isShowAll) {
showAtt = [self getFinalContentStrWithContent:[NSString stringWithFormat:@" %@", str]];
}
NSRange expandRange = [showAtt.string rangeOfString:str];
[showAtt addAttribute:NSForegroundColorAttributeName value:[LCApperance mainYellowColor] range:expandRange];
YYTextHighlight *hi = [YYTextHighlight new];
[showAtt yy_setTextHighlight:hi range:expandRange];
MJWeakSelf;
hi.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
weakSelf.model.isShowAll = !isShowAll;
[weakSelf setupAddMoreBtn];
};
if (isShowAll) {
[attStr appendAttributedString:showAtt];
self.contentLabel.truncationToken = nil;
} else {
YYLabel *seeMore = [YYLabel new];
seeMore.attributedText = showAtt;
[seeMore sizeToFit];
NSAttributedString *truncationToken = [NSAttributedString yy_attachmentStringWithContent:seeMore contentMode:UIViewContentModeRight attachmentSize:showAtt.size alignToFont:showAtt.yy_font alignment:YYTextVerticalAlignmentCenter];
self.contentLabel.truncationToken = truncationToken;
}
YYTextLayout *layoutWidth = [YYTextLayout layoutWithContainerSize:CGSizeMake(LCDeviceWidth - LC_X(87), CGFLOAT_MAX) text:attStr.copy];
//文本高度
CGFloat contentH = layoutWidth.textBoundingSize.height;
CGFloat scrollH = contentH;
// 最大限制<場景分帶鏈接和不帶鏈接>
CGFloat linkH = self.leftImageView.isHidden ? 0 : LC_DeviceX(24);
CGFloat maxLimit = [LCPathTools checkIsJsonString:self.model.content] ? LC_DeviceX(112)+linkH : LC_DeviceX(136)+linkH;
if (isShowAll) {
if (contentH > maxLimit) {
scrollH = maxLimit;
}
} else {
if (contentH > LC_X(44)) {
scrollH = LC_X(40)+linkH;
contentH = LC_X(40);
}
}
[self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(scrollH);
}];
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(contentH);
make.bottom.equalTo(self.scrollView.mas_bottom).offset(-linkH);
}];
} else {
CGFloat linkH = self.leftImageView.isHidden ? 0 : LC_DeviceX(24);
[self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(44+linkH);
}];
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(44);
}];
}
self.contentLabel.attributedText = attStr;
}
七十九、Xcode15 iOS17模擬器文件安裝命令
xcrun simctl runtime add iOS_17_Simulator_Runtime.dmg