1.Navigationbar
在iOS15中,UINavigationBar默認(rèn)是透明的,首次顯示的時(shí)候會(huì)以邊緣外觀樣式的形式展示
ios14 ios15 navigationbar對比如下圖

scrollEdgeAppearance 適配方式:
///Describes the appearance attributes for the navigation bar to use when an associated UIScrollView has reached the edge abutting the bar (the top edge for the navigation bar). If not set, a modified standardAppearance will be used instead.
@property (nonatomic, readwrite, copy, nullable) UINavigationBarAppearance *scrollEdgeAppearance UI_APPEARANCE_SELECTORAPI_AVAILABLE(ios(13.0));
- (void)newNavBarConfig{
UINavigationBar* navigationBar = self.navigationController.navigationBar;
UINavigationBarAppearance* barApp = [[UINavigationBarAppearance alloc] init];
//字體的樣式
barApp.titleTextAttributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:30],
NSForegroundColorAttributeName: [UIColor blueColor]
};
//改變返回按鈕的樣式
UIBarButtonItemAppearance* backAppearance = [[UIBarButtonItemAppearance alloc] initWithStyle:UIBarButtonItemStylePlain];
UIBarButtonItemStateAppearance* normarl = backAppearance.normal;
normarl.titleTextAttributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:30],
NSForegroundColorAttributeName: [UIColor redColor]
};
barApp.backButtonAppearance = backAppearance;
[barApp setBackIndicatorImage:[UIImage imageNamed:@"search@2x"] transitionMaskImage:[UIImage imageNamed:@"search@2x"]];
//Done按鈕的樣式
UIBarButtonItemAppearance* doneppearance = [[UIBarButtonItemAppearance alloc] initWithStyle:UIBarButtonItemStyleDone];
UIBarButtonItemStateAppearance* normarl1 = doneppearance.normal;
normarl1.titleTextAttributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:20],
NSForegroundColorAttributeName: [UIColor blackColor]
};
barApp.doneButtonAppearance = doneppearance;
//設(shè)置背景圖片
barApp.backgroundImageContentMode = UIViewContentModeScaleAspectFit;
barApp.backgroundImage = [UIImage imageNamed:@"背景"];
//常規(guī)樣式
navigationBar.standardAppearance = barApp;
//邊緣外觀樣式
barApp.shadowColor = [UIColor clearColor];
barApp.shadowImage = [UIImage new];
barApp.backgroundImage = nil;
barApp.backgroundColor = [UIColor greenColor];
navigationBar.scrollEdgeAppearance = barApp;
}
適配方案:
在navvbar首次顯示的時(shí)候,將以前的樣式配置,統(tǒng)一更換成UINavigationBarAppearance配置。并且賦值給standardAppearance普通外觀樣式 , 且讓scrollEdgeAppearance = standardAppearance。
2.Tabbar
tabbar的問題和navigationBar的問題屬于同一類,tabbar背景顏色設(shè)置失效,字體設(shè)置失效,陰影設(shè)置失效問題.
同時(shí)也新增scrollEdgeAppearance屬性,當(dāng)關(guān)聯(lián)的scrollview滑動(dòng)到最底部的時(shí)候,tabbar的scrollEdgeAppearance邊緣外觀屬性被展示出來。
- (void)setNewBarConfig{
UITabBarAppearance* appBar = [[UITabBarAppearance alloc] init];
appBar.backgroundColor = [UIColor redColor];
appBar.stackedLayoutAppearance.normal.titleTextAttributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:20],
NSForegroundColorAttributeName: [UIColor whiteColor]
};
appBar.stackedLayoutAppearance.selected.titleTextAttributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:30],
NSForegroundColorAttributeName: [UIColor purpleColor]
};
// appBar.backgroundImage = [UIImage imageNamed:@"背景"];//依然有效
self.tabBar.scrollEdgeAppearance = appBar;
appBar.backgroundColor = [UIColor greenColor];
appBar.shadowColor = [UIColor clearColor];
self.tabBar.standardAppearance = appBar;
}
適配方案:
在tabbar首次顯示的時(shí)候,將以前的樣式配置,統(tǒng)一更換成UITabBarAppearance配置。并且賦值給standardAppearance普通外觀樣式 。
3.sheetPresentationController
通過它可以控制 Modal 出來的 UIViewController 的顯示大小,且可以通過拖拽手勢在不同大小之間進(jìn)行切換。只需要在跳轉(zhuǎn)的目標(biāo)
large 模式 medium模式

- (void)enterNextPage3{
Test2ViewController* VC = [Test2ViewController new];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:VC];
UISheetPresentationController* sheet = nav.sheetPresentationController ;
sheet.detents = @[[UISheetPresentationControllerDetent largeDetent],[UISheetPresentationControllerDetent mediumDetent]];//同時(shí)存在large模式和medium模式
sheet.prefersGrabberVisible = YES;//頂部出現(xiàn)一個(gè)抓取器
[self presentViewController:nav animated:YES completion:nil];
}
4.UIButtonConfiguration
UIButton支持更多配置。UIButton.Configuration是一個(gè)新的結(jié)構(gòu)體,它指定按鈕及其內(nèi)容的外觀和行為。它有許多與按鈕外觀和內(nèi)容相關(guān)的屬性,如cornerStyle、baseForegroundColor、baseBackgroundColor、buttonSize、title、image、subtitle、titlePadding、imagePadding、contentInsets、imagePlacement等。
- (void)newBtn{
NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:@"登錄"];
[attributedTitle setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30],NSForegroundColorAttributeName:[UIColor yellowColor]} range:NSMakeRange(0, 1)];
[attributedTitle setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor blueColor]} range:NSMakeRange(1, 1)];
UIButtonConfiguration * configuration = [UIButtonConfiguration tintedButtonConfiguration];
// configuration.attributedTitle = attributedTitle;
configuration.title = @"登錄";
configuration.subtitle = @"請輸入賬號";
configuration.image = [UIImage imageNamed:@"search"];
configuration.imagePadding = 30;//
configuration.cornerStyle = UIButtonConfigurationCornerStyleLarge;
//二段文字的間距
configuration.titlePadding = 20;
//圖片與文本的間距
configuration.imagePadding = 20;
//文本的居中方式
configuration.titleAlignment = UIButtonConfigurationTitleAlignmentCenter;
//圖片顯示的位置(上下左右)
configuration.imagePlacement = NSDirectionalRectEdgeTrailing;
//背景色
configuration.baseBackgroundColor = [UIColor yellowColor];
//自帶的button大小
// configuration.buttonSize = UIButtonConfigurationSizeLarge;
//文字的顏色
configuration.baseForegroundColor = [UIColor redColor];
//內(nèi)容的間距
configuration.contentInsets = NSDirectionalEdgeInsetsMake(30, 30, 30, 30);
configuration.activityIndicatorColorTransformer = ^UIColor * _Nonnull(UIColor * _Nonnull color) {
return [UIColor blueColor];
};
//
// configuration.showsActivityIndicator = YES;
UIButton* btn = [UIButton buttonWithConfiguration:configuration primaryAction:nil];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(update:) forControlEvents:UIControlEventTouchUpInside];
//樣式、狀態(tài)變化回調(diào)(選中、未選中、高亮......)
btn.configurationUpdateHandler = ^(UIButton* btn){
//或者處理其他的邏輯(比如當(dāng)用戶名和密碼都同時(shí)存在的時(shí)候,即可改變狀態(tài))
UIButtonConfiguration* config = btn.configuration;
if(config.showsActivityIndicator){
config.title = @"正在加載中...";
}else{
config.title = @"登錄";
}
btn.configuration = config;
};
//當(dāng)設(shè)置了config之后,下面的這些已經(jīng)無效了
// btn.titleLabel.textAlignment = NSTextAlignmentRight;
// [btn.titleLabel setFont:[UIFont boldSystemFontOfSize:40]];
// btn.subtitleLabel.font = [UIFont systemFontOfSize:5];
// [btn.subtitleLabel setTextColor:[UIColor blackColor]];
[btn sizeToFit];
btn.center = CGPointMake(self.view.frame.size.width/4, self.view.center.y + 50);
self.btn = btn;
// btn.layer.cornerRadius = btn.frame.size.height/2;
// btn.layer.masksToBounds = YES;
}
- (void)update:(UIButton*)btn{
UIButtonConfiguration * con = btn.configuration;
con.showsActivityIndicator = !btn.configuration.showsActivityIndicator;
btn.configuration = con;
}

5.UITableView
從 iOS 15 開始,TableView 增加sectionHeaderTopPadding屬性,默認(rèn)情況sectionHeaderTopPadding會(huì)有22個(gè)像素的高度,及默認(rèn)情況,TableView section header增加22像素的高度
self.tableView.sectionHeaderTopPadding = 0
6.CLLocationButton
點(diǎn)擊實(shí)現(xiàn)定位授權(quán)
- (void)locationBtn{
CLLocationButton* btn = [[CLLocationButton alloc] init];
btn.label = CLLocationButtonLabelCurrentLocation;
btn.fontSize = 20;
btn.icon = CLLocationButtonIconArrowFilled;
btn.tintColor = [UIColor systemPinkColor];
btn.backgroundColor = [UIColor yellowColor];
[self.view addSubview:btn];
[btn sizeToFit];
btn.userInteractionEnabled = YES;
btn.layer.transform = CATransform3DMakeTranslation(100, 200, 0);
}
- (void)locationBtn{
CLLocationButton* btn = [[CLLocationButton alloc] init];
btn.label = CLLocationButtonLabelCurrentLocation;
btn.fontSize = 20;
btn.icon = CLLocationButtonIconArrowFilled;
btn.tintColor = [UIColor systemPinkColor];
btn.backgroundColor = [UIColor yellowColor];
[self.view addSubview:btn];
[btn sizeToFit];
btn.userInteractionEnabled = YES;
btn.layer.transform = CATransform3DMakeTranslation(100, 200, 0);
}
7.UIImage
開啟線程執(zhí)行裁剪功能,執(zhí)行完畢之后要回到主線程去操作
[image prepareThumbnailOfSize:CGSizeMake(50, 100) completionHandler:^(UIImage * _Nullable image) {
//此處開啟一個(gè)新線程進(jìn)行
NSLog(@"裁剪完畢%@",[NSThread currentThread]);
dispatch_async(dispatch_get_main_queue(), ^{//回歸到主線程
[self afterImage:image];
});
}];
8.額外補(bǔ)充: cell.configurationUpdateHandler'
tableviewCell的樣式配置UIListContentConfiguration、UIBackgroundConfiguration
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
UIListContentConfiguration * config = cell.defaultContentConfiguration ;
UIBackgroundConfiguration * config2 = [UIBackgroundConfiguration listPlainCellConfiguration];
config2.cornerRadius = 10;
config2.backgroundColor = [UIColor purpleColor];
config.text = [NSString stringWithFormat:@"樣式內(nèi)容%ld",indexPath.row];
config.image = [UIImage imageNamed:@"search"];
cell.contentConfiguration = config;//內(nèi)容樣式
cell.backgroundConfiguration = config2;//背景樣式
cell.configurationUpdateHandler = ^(__kindof UITableViewCell * _Nonnull cell, UICellConfigurationState * _Nonnull state) {
UIBackgroundConfiguration* confi = cell.backgroundConfiguration;
NSLog(@"觸發(fā)state.isSelected = %d,state.isSwiped = %d,state.isExpanded = %d,state.isHighlighted = %d,state.isFocused = %d,state.isReordering = %d state.isEditing = %d", state.isSelected,state.isSwiped,state.isExpanded,state.isHighlighted,state.isFocused,state.isReordering,state.isEditing);
if(state.isSelected){//可以用來做”已讀置灰的功能需求“,未必就是變顏色,或者是其他的交互
confi.backgroundColor = [UIColor lightGrayColor];
}else{
confi.backgroundColor = [UIColor whiteColor];
}
if(state.isHighlighted == NO){//當(dāng)不在高亮的時(shí)候 取消掉選中狀態(tài)
cell.selected = NO;
}
cell.backgroundConfiguration = confi;
};
cell.automaticallyUpdatesContentConfiguration = YES;
cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];//優(yōu)先級小于config
return cell;
}