小编Rob*_*ler的帖子

底部导航抽屉不显示 (Swift)

我目前正在开发一个 iOS 应用程序,我想使用 material-io 的底部导航抽屉。所以我做到了,就像网站上的示例中所解释的那样。但是当我展示导航抽屉时,ViewController 只会变暗一点,并且没有显示抽屉的 contentView。

这是我的代码:

import Foundation
import UIKit
import MaterialComponents

class CreateSubjectView: UIViewController, UITextFieldDelegate {
    ...
    override func viewDidLoad() {
        ...
        let bottomDrawerViewController = MDCBottomDrawerViewController()
        self.modalPresentationStyle = .popover
        let newViewController = self.storyboard?.instantiateViewController(withIdentifier: "TEST")
        bottomDrawerViewController.contentViewController = newViewController

        present(bottomDrawerViewController, animated: true, completion: nil)    
        ...
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

ios swift material-design

7
推荐指数
1
解决办法
925
查看次数

SwiftUI iOS Widget – 一段时间后图像被裁剪

我正在使用 SwiftUI 创建 iOS 14+ Widget,我面临着非常奇怪的情况。问题是我的小部件中只有一个“完整小部件”图像(也许值得注意的是,它是从互联网下载的,但在显示其已加载并注入时UIImage),该图像正确显示如下:

在此输入图像描述

但过了一段时间,更多的 iPhone 解锁 BOOM 后,我得到了这个:

在此输入图像描述

一些观察:

  • 家庭也会发生这种情况systemLarge- 图像宽度的相同百分比被裁剪
  • 图像始终以完全相同的宽度百分比水平裁剪
  • 当我的壁纸不仅仅是纯黑色时,裁剪部分也会填充黑色
  • 无论我有什么用户界面风格(浅色/深色),裁剪的部分都会填充黑色

为了方便起见,我创建了导致错误的最小示例:

所以,我有这个EntryView

struct EntryView: View {

    var viewModel: EntryViewModel

    var body: some View {
        Image(uiImage: image)
            .resizable()
            .scaledToFill()
    }
}
Run Code Online (Sandbox Code Playgroud)

用作Widget其自身的内容

struct SomeWidget: Widget {

    var body: some WidgetConfiguration {
        StaticConfiguration(
            kind: xxx,
            provider: SomeWidgetTimelineProvider(xxx)
        ) { item in
            view(for: item)
        }
            .configurationDisplayName(xxx)
            .description(xxx)
            .supportedFamilies([.systemMedium, .systemLarge])
    }

    private func view(for item: Item) -> some View { …
Run Code Online (Sandbox Code Playgroud)

ios swift widgetkit swiftui

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

无法以编程方式将情节提要中设置的颜色更改为xcassets目录中的颜色

当我在情节提要中将某些属性的颜色(例如textColormy UILabel)设置为在xcassets目录中作为“新建颜色集”创建的颜色时

在此处输入图片说明

那么我无法在第一次尝试时以编程方式更改此颜色:

label.textColor = UIColor(named: "HighlightedGreen")
Run Code Online (Sandbox Code Playgroud)

...请注意,我是从数据源方法调用它的cellForItemAt

哈克: 我可以通过在情节提要中将此颜色设置为从颜色选择器中拾取的任何其他颜色来解决该问题,但是我想知道为什么会这样。

那么,为什么会这样呢?

xcode colors uicolor xcasset swift

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

iOS 17 交互式小部件 - 删除按钮背景和填充

我正在尝试创建新的 iOS 17 交互式小部件。为了能够添加“操作”,我想使用新的init(_:intent:)初始化程序,Button它允许我在按下按钮时执行给定的意图。

问题是,我的按钮应该只是带有微笑图像的绿色内部矩形,但系统添加了自己的带有填充的背景。有什么办法可以去除吗?

示例代码:

Button(intent: MyIntent()) {
    MyLabel()
}
Run Code Online (Sandbox Code Playgroud)

看起来如何:

在此输入图像描述

ios swift widgetkit ios17

4
推荐指数
1
解决办法
848
查看次数

Swift如何为不同语言本地化一个数组

我正在尝试为不同的语言本地化一个数组.

我想要本地化的数组看起来像:

var watch = ["This watch is blue", "this watch is red", "this watch is white "]
Run Code Online (Sandbox Code Playgroud)

我已经有字符串localizable,我正在使用该方法,NSLocalizedString但我不知道如何使用所有不同的描述本地化数组.

感谢您的帮助

localization swift

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

如何传递协议枚举数组在swift 4.0中运行?

我有一个类使用协议调用另一个类中的函数:

func calculateTableSize () {            
    // doing some stuff  
    // the call to the other function using the protocol
    summaryPresenter?.onCalculateTableSizeDone()     
}
Run Code Online (Sandbox Code Playgroud)

我想使用此函数传递一个类型为enum的数据数组:

class SummaryInteractor: SummaryScreenInteractorFunctionsProtocol {

    //sections
    enum Section: Int, CaseIterable {
        case header = 0, description, diagnoses, perscription, notes, addFaxHeadline,  addFax, addEmailHeadline, addEmails, givePermissionHeadline, selecAnswer, addNewEmail,addNewFax, removableText, headlineEmpty
    }

    var sectionData: [Section] = [
        .header
    ]

...
...
Run Code Online (Sandbox Code Playgroud)

问题显然是我不能在我的协议中添加这一行(这是我想要实现的):

//what will be written in the presenterFromTheInteractor
protocol SummaryScreenInteractorProtocol {
    func onCalculateTableSizeDone(data: [Section])
}
Run Code Online (Sandbox Code Playgroud)

因为那时协议(以及所有其他类都不会知道这个新的Enum类型,什么是Selection.

因此,它出错了:

func calculateTableSize () { …
Run Code Online (Sandbox Code Playgroud)

swift

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