1、UITextField修改placeholder顏色
私有屬性_placeholderLabel 被禁止訪問(wèn)了
Swift:
textField.setValue(.white, forKeyPath: "_placeholderLabel.textColor")
修改為
let attributedString = NSMutableAttributedString(string: "輸入", attributes: [NSAttributedString.Key.foregroundColor : BaseColor.PlaceHolderColor])
textField.attributedPlaceholder = attributedString
OC:
[textField setValue:[UIColor white] forKeyPath:@"_placeholderLabel.textColor"];
修改為
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"輸入" attributes:@{NSForegroundColorAttributeName: [UIColor red]}];
2、present控制器模態(tài)跳轉(zhuǎn)樣式
Swift:
self.modalPresentationStyle = .fullScreen
OC:
self.modalPresentationStyle = UIModalPresentationFullScreen;
3、全局關(guān)閉暗黑模式
在info.plist中添加User Interface Style,設(shè)置為L(zhǎng)ight
或者:
if(@available(iOS 13.0,*)) {
self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}
4、DeviceToken獲取方式
if (![deviceToken isKindOfClass:[NSData class]]) return;
const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSLog(@"deviceToken:%@",hexToken);
5、廢棄的 LaunchImage
從2020年4月開始,所有使? iOS13 SDK的App將必須使用LaunchScreen
6、UISegmentedControl變化
iOS13默認(rèn)樣式是白底黑字,不能通過(guò)tintColor修改選中背景顏色,新增了selectedSegmentTintColor屬性用以修改選中的顏色
7、CNCopyCurrentNetworkInfo
iOS13 以后只有開啟了 Access WiFi Information capability,才能獲取到SSID和BSSID,應(yīng)用還需要符合下列三項(xiàng)條件中的至少一項(xiàng)才能得到正確的值:
1、獲得定位服務(wù)權(quán)限。
2、使用NEHotspotConfiguration來(lái)配置 WiFi 網(wǎng)絡(luò)的應(yīng)用。
3、目前正處于啟用狀態(tài)的 VPN 應(yīng)用。
Swift:
func getWifiName() -> String? {
var wifiName = ""
let wifiInterfaces = CNCopySupportedInterfaces()
if wifiInterfaces == nil {
return nil
}
let interfaceArr = CFBridgingRetain(wifiInterfaces!) as! Array<String>
if interfaceArr.count > 0 {
let interfaceName = interfaceArr[0] as CFString
let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
if (ussafeInterfaceData != nil) {
let interfaceData = ussafeInterfaceData as! Dictionary<String, Any>
wifiName = interfaceData["SSID"]! as! String
}
}
return wifiName
}
OC:
-(void)getWiFiName {
NSString *wifiName = nil;
CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();
if (!wifiInterfaces) {
return nil;
}
NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;
for (NSString *interfaceName in interfaces) {
CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName));
if (dictRef) {
NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef;
NSLog(@"network info -> %@", networkInfo);
wifiName = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];
CFRelease(dictRef);
}
}
CFRelease(wifiInterfaces);
return wifiName;
}
}
8、廢棄UIWebView,WKWebView 中測(cè)量頁(yè)面內(nèi)容高度的方式變更
<iOS13
document.body.scrollHeight
>=iOS13
document.documentElement.scrollHeight
9、UISearchBar 黑線處理導(dǎo)致崩潰
之前為了處理搜索框的黑線問(wèn)題,通常會(huì)遍歷 searchBar 的 subViews,找到并刪除 UISearchBarBackground,在 iOS13 中這么做會(huì)導(dǎo)致 UI 渲染失敗,然后直接崩潰
解決辦法:設(shè)置 UISearchBarBackground 的 layer.contents 為 nil
for (UIView *view in _searchBar.subviews.lastObject.subviews) {
if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
view.layer.contents = nil;
break;
}
}
//崩潰 api
UITextField *textField = [searchBar valueForKey:@"_searchField"];
//方案1:使用 iOS 13 的新屬性 searchTextField
searchBar.searchTextField.placeholder = @"search";
//方案2:遍歷獲取指定類型的屬性
- (UIView *)findViewWithClassName:(NSString *)className inView:(UIView *)view{
Class specificView = NSClassFromString(className);
if ([view isKindOfClass:specificView]) {
return view;
}
if (view.subviews.count > 0) {
for (UIView *subView in view.subviews) {
UIView *targetView = [self findSpecificView:className inView:subView];
if (targetView != nil) {
return targetView;
}
}
}
return nil;
}
// 調(diào)用方法
UITextField *textField = [self findViewWithClassName:@"UITextField" inView:_searchBar];
//崩潰 api
[searchBar setValue:@"取消" forKey:@"_cancelButtonText"];
// 替代方案,用同上的方法找到子類中 UIButton 類型的屬性,然后設(shè)置其標(biāo)題
UIButton *cancelButton = [self findViewWithClassName:NSStringFromClass([UIButton class]) inView:searchBar];
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
10、iOS13中使用UISearchDisplayController崩潰
使用 UISearchController 替換 UISearchBar + UISearchDisplayController組合
11、UITabbar無(wú)法通過(guò)設(shè)置shadowImage去掉上面的線
Swift:
if #available(iOS 13, *) {
let appearance = self.tabBar.standardAppearance.copy()
appearance.backgroundImage = UIImage()
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
self.tabBar.standardAppearance = appearance
} else {
self.tabBar.shadowImage = UIImage()
self.tabBar.backgroundImage = UIImage()
}
OC:
if (@available(iOS 13.0, *)) {
UITabBarAppearance* appearance = self.tabBar.standardAppearance.copy;
appearance.backgroundImage = [UIImage new];
appearance.shadowImage = [UIImage new];
appearance.shadowColor = [UIColor clearColor];
// Title adjustment
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffsetMake(0, -12);
self.tabBar.standardAppearance = appearance;
} else {
self.tabBar.shadowImage = [UIImage new];
self.tabBar.backgroundImage = [UIImage new];
}
12、iOS13菜單欄文字顏色變藍(lán)問(wèn)題
if #available(iOS 13.0, *) {
UITabBar.appearance().unselectedItemTintColor = UIColor(hex: 0x888888)
UITabBar.appearance().tintColor = UIColor(hex: 0x333333)
}