小编Kyl*_*bbs的帖子

为 SwiftUI Text 视图提供固定宽度并使文本换行至不定高度

澄清问题的主要编辑

我想要的:对于与Text屏幕左侧或右侧对齐的视图扩展到某个最大宽度,并且当文本达到该长度时,它不会超出该长度。当要显示的文本太长时,视图Text只是简单地增加高度以容纳额外的文本。Apple 的消息应用程序就是一个这样的例子:发送的消息一直向右对齐,但即使它们很长,左侧仍然有一个空白空间(聊天气泡的宽度仅达到 75%)屏幕的宽度)。

我有一些硬编码值的代码来提供示例:

struct ContentView: View {
    let messages = [
        "Hello.",
        "Hi",
        "Text so long that it could reach all the way to the other side of the screen, we only want it to take up a width of about 75% of the screen though starting from the left. That is the main issue of this post.",
        "Yeah. This message is also long enough to take up the full width of …
Run Code Online (Sandbox Code Playgroud)

swift swiftui

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

在C中将int转换为char

现在我试图在C编程中将int转换为char.经过研究,我发现我应该能够这样做:

int value = 10;
char result = (char) value;
Run Code Online (Sandbox Code Playgroud)

我想要的是返回'A'(以及0-9返回'0' - '9'),但这会返回一个我认为的新行字符.我的整个函数看起来像这样:

char int2char (int radix, int value) {
  if (value < 0 || value >= radix) {
    return '?';
  }

  char result = (char) value;

  return result;
}
Run Code Online (Sandbox Code Playgroud)

c type-conversion

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

标签 统计

c ×1

swift ×1

swiftui ×1

type-conversion ×1