今天遇到一個問題昏翰,iOS13?attributedPlaceholder顏色設置無效
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"搜索" attributes:
? ? @{NSForegroundColorAttributeName:[UIColor redColor]}
? ? ];
? ? searchTextField.attributedPlaceholder = attrString;
就是這么設置的捏萍,然后發(fā)現顏色字體顏色始終為灰色。但是同樣的代碼11奕扣,12系統(tǒng)是可以的
百度了半天都沒有找到辦法。不過最終還是找到一個可行的辦法
就是在vc 的viewWillAppear方法中掌敬,添加
if(@available(iOS13.0, *)) {
? ? ? ? dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
? ? ? ? ? ? usleep(3000);
? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{
? ? ? ? ? ? ? ? self.searchBar.searchTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"搜索"
? ? ? ? ? ? ? ? attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
? ? ? ? ? ? });
? ? ? ? });
? ? }
不過我看別人也沒有給出其他解釋惯豆,感覺應該是13系統(tǒng),在顯示的過程中又重新覆蓋了默認色奔害,導致顯示始終為灰色