小编ste*_*hen的帖子

有没有办法修复 swiftUI 中的按钮宽度?

我尝试修复swiftUI中的按钮宽度,但是宽度是指向.frame(width: )还是固定.fixedSize(horizontal: true, vertical: false)修饰符中,或两者兼而有之,它仍然不起作用。该按钮只是根据其内容长度缩小或扩展。我该如何解决?

\n

请看下面的代码和图片:

\n
struct ContentView: View {\n    var body: some View {\n        let days = [0, 1, 2, 3, 4]\n        \n        let dayWeatherList = ["Sunday, Sunny",\n                                  "Monday, Sunny",\n                                  "Tuesday, Sunny",\n                                  "Wednesday, Sunny",\n                                  "Thursday, Sunny"]\n        \n        let aqiList = [aqiItem(aqi: 6, color: .green),\n                               aqiItem(aqi: 123, color: .orange),\n                               aqiItem(aqi: 25, color: .green),\n                               aqiItem(aqi: 345, color: .red),\n                               aqiItem(aqi: 56, color: .yellow)]\n        \n        VStack {\n            ForEach(days, id: \\.self) { index in\n                let dayWeatherInfo = dayWeatherList[index]\n …
Run Code Online (Sandbox Code Playgroud)

uibutton ios swiftui

8
推荐指数
1
解决办法
8815
查看次数

iOS 15 UIButton配置标题lineBreakMode不起作用?

在iOS 14或更早版本中,如果我们想设置一个titleLabel's属性,我们可以简单地使用

button.titleLabel?.lineBreakMode = .byTruncatingTail
Run Code Online (Sandbox Code Playgroud)

或缩小标题文本:

button.titleLabel?.adjustsFontSizeToFitWidth = true
button.titleLabel?.minimumScaleFactor = 0.5
Run Code Online (Sandbox Code Playgroud)

但是更新到iOS 15最新的API后UIButton.Configuration,上面的代码就不再起作用了,按钮只是扩大了高度,这绝对不是我想要的方式,请看下面:

在此输入图像描述

使用 iOS 15 时有什么解决方案可以恢复lineBreakMode吗?minimumScaleFactorUIButton.Configuration

uibutton uikit ios swift

8
推荐指数
1
解决办法
842
查看次数

为什么导航栏背景颜色没有改变?

当用户选择不同的主题样式时,我需要更改导航栏背景颜色。

但奇怪的是,用户选择“深色”模式后,进入后台,然后回到前台,如果用户想改回“浅色”模式,导航栏仍然是黑色风格,有一个“_UIVisualEffectBackdropView”保持黑暗。

但如果用户在进入后台之前选择“Light”模式,则一切正常。

我该如何修复这个错误?下面是代码和图片:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch indexPath.row {
    case 0:
        self.changeToLightColor()
    default:
        self.changeToDarkColor()
    }
}

private func changeToLightColor() {
    self.navigationController?.navigationBar.barStyle = .default
    
    let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemBlue]
    self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}

private func changeToDarkColor() {
    self.navigationController?.navigationBar.barStyle = .black
    
    let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemGreen]
    self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

非常感谢您的帮助和提前答复!

uinavigationbar uinavigationcontroller ios swift ios13

5
推荐指数
1
解决办法
3081
查看次数

如何使用Swift将字符串加密到base64中的sha1?

我希望使用Swift将privateKey和publicKey加载到base64中的sha1,但是输出不是我在Codeclemy中尝试的PHP urlencode base64_encode中看到的:" https://www.codecademy.com/courses/web-beginner- en-StaFQ/0/3?curriculum_id = 5124ef4c78d510dd89003eb8 ".

请参阅Swift和Codecademy中的以下代码:

迅速:

//pls see func dataFromHexadecimalString() details here "http://stackoverflow.com/questions/26501276/convert-string-to-hex-string-in-swift/26502285#26502285" 

extension String {

func dataFromHexadecimalString() -> NSData? {
    let trimmedString = self.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<> ")).stringByReplacingOccurrencesOfString(" ", withString: "")

    var error: NSError?
    let regex = NSRegularExpression(pattern: "^[0-9a-f]*$", options: .CaseInsensitive, error: &error)
    let found = regex?.firstMatchInString(trimmedString, options: nil, range: NSMakeRange(0, count(trimmedString)))
    if found == nil || found?.range.location == NSNotFound || count(trimmedString) % 2 != 0 {
        return nil
    }

    let data = NSMutableData(capacity: count(trimmedString) / 2) …
Run Code Online (Sandbox Code Playgroud)

php base64 hmacsha1 ios swift

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