当我尝试使用最新版本的Swift 设置label1为第一个字母时,我在最后一行收到错误string.如何解决这个问题?
let preferences = UserDefaults.standard
let name1 = "" + preferences.string(forKey: "name")!
let name2 = name1
label1.text = name2.substring(from: 0)
Run Code Online (Sandbox Code Playgroud) func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
Run Code Online (Sandbox Code Playgroud)
所以简单地说,我使用该函数获取我的文件名.它现在正确返回,如何使用Swift 3删除此文件?我怎么能像这样读回图像UIImageJPEGRepresentation?
let image_data = UIImageJPEGRepresentation(self.commons.correctlyOrientedImage(image: self.imageSelected.image!),0.5)
Run Code Online (Sandbox Code Playgroud)
我做了以下,它没有工作
Run Code Online (Sandbox Code Playgroud)let filename = getDocumentsDirectory().appendingPathComponent("l.png") letfileManager = FileManager.default var filePath = filename //检查文件是否存在
Run Code Online (Sandbox Code Playgroud)if fileManager.fileExists(atPath: filePath.absoluteString) { // Delete file try fileManager.removeItem(atPath: filePath.absoluteString) } else { print("File does not exist") }
我保存这样的文件
Run Code Online (Sandbox Code Playgroud)let filename = getDocumentsDirectory().appendingPathComponent("COPY111.PNG") try? image_data?.write(to: filename)
但我无法从下面提供的答案中删除它
这 2 个作品
Run Code Online (Sandbox Code Playgroud)<TextView android:id="@+id/item2" android:layout_below="@id/item1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="middle" android:singleLine="true" android:paddingLeft="10dp" android:paddingRight="120dp" android:paddingTop="5dp" /> <TextView android:id="@+id/item2" android:layout_below="@id/item1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="3" android:paddingLeft="10dp" android:paddingRight="120dp" android:paddingTop="5dp" />
这不起作用
Run Code Online (Sandbox Code Playgroud)<TextView android:id="@+id/item2" android:layout_below="@id/item1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="middle" android:maxLines="3" android:paddingLeft="10dp" android:paddingRight="120dp" android:paddingTop="5dp" />
那么,什么是解决方案。为什么会有这种不一致?为什么当我有椭圆形结束和最大线时它起作用,但当我有椭圆形中线和最大线时不起作用。为什么它适用于单线以及椭圆中间而不适用于最大线?谢谢你的帮助。我需要 ellipsize middle 和 maxlines 3。
在实施之前,我想有一个想法.这就是我认为它的工作原理,用户首次使用用户名和密码登录我的应用程序时,我保存了用户并传入了我的应用程序.第二次,用户愿意进入应用程序我给他选择使用指纹输入用户名+密码.如果他使用指纹,我会验证它,如果验证成功,我会使用保存的用户名和密码来调用登录API.这种思维方式,流畅吗?