iOS13不允許 valueForKey、setValue: forKey 獲取和設置私有屬性
iOS13以前:
// textField
[_textField setValue:[UIColor orangeColor] forKeyPath:@"_placeholderLabel.textColor"];
// textView
[_textView setValue:創(chuàng)建的label的對象 forKey:@"_placeholderLabel"];
iOS13以后可以修改為:
// 通過 runtime 獲取對象屬性
// instance:textField或者textView對象
// name:屬性名字例如(@"_placeholderLabel")
Ivar ivar = class_getInstanceVariable(instance.class, name.UTF8String);
UILabel *label = object_getIvar(aTextField, ivar);
// 通過設置label修改
iOS13之后模態(tài)present跳轉(zhuǎn)后頁面沒有充滿屏幕
- 因為iOS13之后默認類型為 UIModalPresentationPageSheet 導致
解決辦法:
設置 modalPresentationStyle 為 UIModalPresentationFullScreen
iOS13之后 deviceToken 獲取方式改變
- 修改方式如下:
NSString *tokenStr = nil;
if (@available(iOS 13.0, *)) {
// 適配iOS13
NSMutableString *deviceStr = [NSMutableString string];
const char *bytes = deviceToken.bytes;
NSInteger count = deviceToken.length;
for (int i = 0; i < count; i++) {
[deviceStr appendFormat:@"%02x", bytes[i]&0x000000FF];
}
tokenStr = deviceStr;
}else {
// iOS13以前
NSString *deviceStr = [deviceToken description];
if ((deviceStr.length > 0) && ([deviceStr rangeOfString:@"<"].location != NSNotFound)) {
NSString *tk0 = [deviceStr stringByReplacingOccurrencesOfString:@"<"withString:@""];
NSString *tk1 = [tk0 stringByReplacingOccurrencesOfString:@">"withString:@""];
tokenStr = [tk1 stringByReplacingOccurrencesOfString:@" "withString:@""];
}
}
NSLog(@"%@",tokenStr);