小编Pet*_*lie的帖子

EXIF数据读写

我搜索了从图片文件中获取EXIF数据并将其写回Swift.但我只能找到不同语言的预定义库.

我还发现了对"CFDictionaryGetValue"的引用,但是我需要哪些密钥来获取数据?我该怎么写回来?

exif swift

9
推荐指数
2
解决办法
5194
查看次数

Swift 3:设置Finder标签颜色

我正在尝试设置取景器显示的彩色标签.我所知道的唯一功能是setResourceValue.但这需要本地化名称!

我可以想象我的母语和英语,但我不知道所有其他人.我不敢相信,这应该是这样的.

是转换函数,它采用像enum或int这样的标准参数并提供本地化的颜色名称?

我有一个运行的部分,但只有两种语言(德语和英语):

let colorNamesEN = [ "None", "Gray", "Green", "Purple", "Blue", "Yellow", "Red", "Orange" ]
let colorNamesDE = [ "",     "Grau", "Grün",  "Lila",   "Blau", "Gelb",   "Rot", "Orange" ]

public enum TagColors : Int8 {
    case None = -1, Gray, Green, Purple, Blue, Yellow, Red, Orange, Max
}

//let theURL : NSURL = NSURL.fileURLWithPath("/Users/dirk/Documents/MyLOG.txt")

extension NSURL {
    // e.g.  theURL.setColors(0b01010101)
    func tagColorValue(tagcolor : TagColors) -> UInt16 {
        return 1 << UInt16(tagcolor.rawValue)
    }

    func addTagColor(tagcolor : TagColors) -> Bool { …
Run Code Online (Sandbox Code Playgroud)

macos cocoa label finder swift

5
推荐指数
2
解决办法
1463
查看次数

Swift 3:向后搜索字符串

我想向后搜索一个字符串。但是我发现的所有示例都不能在当前的Swift 3.0上运行。我的XCode 8上没有可用的“ .BackwardsSearch”选项。如何实现?例:

let rPos = rIndex(sourceString, searchString)
Run Code Online (Sandbox Code Playgroud)

要么

let rPos = sourceString.rindex(of: searchString)
Run Code Online (Sandbox Code Playgroud)

string indexing reverse swift

3
推荐指数
1
解决办法
2133
查看次数

在 SwiftUI 中设置 TextField 的宽度

使用 TextField 时,我想将其设置为固定宽度,而不管显示的文本长度如何,例如“123456789”的字段宽度,即使内容仅为“1”。

TextField("0", text: $username)
    .textFieldStyle(RoundedBorderTextFieldStyle())
    .fixedSize(horizontal: true, vertical: false)
    .frame(width: 120)
Run Code Online (Sandbox Code Playgroud)

我没有找到任何可以设置宽度的东西。使用框架只会影响周围的框架,但我想设置 TextField 本身的宽度。所以可见宽度应该比它的内容宽。任何想法?

width textfield swiftui

3
推荐指数
1
解决办法
5460
查看次数

在macOS上播放声音

我喜欢在我的应用中播放声音.我发现了很多例子,也可以在Swift 3上编译和运行它们.但是它们总是用于iOS.当在我的应用程序中使用此代码时,AVAudioSession保持未定义.我需要做什么?OSX有什么不同之处吗?

import AVFoundation
...
    var audioPlayer = AVAudioPlayer()
    func PlaySound( ) {
        let alertSound = URL(fileURLWithPath: Bundle.main.path(forResource: "Sound", ofType: "mp3")!)
        do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        } catch _ {
        }
        do {
            try AVAudioSession.sharedInstance().setActive(true)
        } catch _ {
        }
        do {
            audioPlayer = try AVAudioPlayer(contentsOf: alertSound)
        } catch _{
        }
        audioPlayer.prepareToPlay()
        audioPlayer.play()
    }
Run Code Online (Sandbox Code Playgroud)

audio macos avaudiosession swift

2
推荐指数
2
解决办法
2824
查看次数

标签 统计

swift ×4

macos ×2

audio ×1

avaudiosession ×1

cocoa ×1

exif ×1

finder ×1

indexing ×1

label ×1

reverse ×1

string ×1

swiftui ×1

textfield ×1

width ×1