1.UITableView问题
1.UITableView滚动到顶部
有好几种方法 常用:
tableView.setContentOffset(CGPoint.zero, animated: true)
如果有上啦加载更多就会导致滚动位置不准确的问题
解决方法:
tableView.estimatedRowHeight = 0
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0
2.tableView内边距适配
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}else {
automaticallyAdjustsScrollViewInsets = false
}
2.关于UITextField设置了模式为isSecureTextEntry = true 再次编辑时就会清空的问题
解决方法:代理里面监听判断
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let toBeString = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
if textField.isSecureTextEntry {
textField.text = toBeString;
return false
}
return true
}
2,颜色空间Color Space的问题
项目中Xib和Storyboard里面颜色的值一直都是sRGB的模式设置的但是设计师确实用的displayP3的模式,所以就要全部改过来,在github上找到了工具XCode-Color-Fixer 但是里面的颜色模式是写死的需要自己更改,然后依照上面的方法就ok
源代码
#!/usr/bin/php -q
<?php
echo "=== XCode Color Space Fixer ===", "\n";
echo "Any Question? PonyCui@me.com", "\n";
echo "root = ", getcwd(), "\n";
$root = getcwd();
$files = scandir($root);
$isXcodeProj = false;
foreach ($files as $file) {
if (strpos($file,'.xcodeproj') !== false) {
$isXcodeProj = true;
}
}
if ($isXcodeProj) {
echo "isXcodeProj = true", "\n";
}
else {
die("[Error] Not a valid xcode project directory!"."\n");
}
scanInterfaceBuilderFiles($root);
function scanInterfaceBuilderFiles($dir) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file == '.' || $file == '..' || $file == 'Pods') {
continue;
}
else if (is_dir($dir.'/'.$file)) {
scanInterfaceBuilderFiles($dir.'/'.$file);
}
else {
if (strpos($file, '.storyboard') !== false || strpos($file, '.xib') !== false) {
$changed = replaceColorSpace($dir.'/'.$file);
echo 'file = ', $file, " " ,($changed ? "[Change]" : "[OK]"), "\n";
}
}
}
}
function replaceColorSpace($filePath) {
$fileContents = file_get_contents($filePath);
$replaceContents = str_replace('colorSpace="custom" customColorSpace="sRGB"', 'colorSpace="custom" customColorSpace="displayP3"', $fileContents);
if($replaceContents == $fileContents) {
return false;
}
else {
file_put_contents($filePath, $replaceContents);
return true;
}
}