小编Bra*_*rst的帖子

CSS浮动注释与自己的流程

更新

我忍受了赏金,但从未实现过正确的答案.我已经实现了一个适用于我的JS解决方案,但我不打算将答案标记为正确.如果只使用CSS/HTML,我仍然希望看到它.但普遍的共识是,目前还不可能.

目标

CodePen在这里,底部是runnable片段.

我有一些HTML内容,我想用一条直接浮在它上面的小消息进行注释,在最左边,有点像<ruby>注释(但不完全一样).可以有许多内容,每个内容都有自己的注释.内容必须遵循正常的文本流程.这是我目前的HTML:

<div class='item' style='color: red'>
  <div class='annotation'>nope</div>
  <div class='content'>It's a bird, </div>
</div>
<div class='item' style='color: green'>
  <div class='annotation'>still no</div>
  <div class='content'>it's a plane, </div>
</div>
<div class='item' style='color: blue'>
  <div class='annotation'>yeah!</div>
  <div class='content'>it's Superman! </div>
</div>
<div class='item' style='color: orange'>
  <div class='annotation'>muahaha</div>
  <div class='content'>Go get the Kryptonite</div>
</div>
Run Code Online (Sandbox Code Playgroud)

工作实例

下面,句子It's a bird, it's a plane, it's Superman! Go get the Kryptonite有4个独立的部分(4个content),每个部分用不同的颜色表示.每条内容都有自己的内容annotation,上面用斜体显示.

在此输入图像描述

我有这个工作,通过制作内容和注释,float: left并给予注释否定margin …

html css

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

将SwiftUI列表滚动到新选择

如果您有一个SwiftUI列表,该列表允许单选,则可以通过单击列表(大概使它成为按键响应者),然后使用箭头键来更改选择。如果该选择到达可见区域的末尾,它将滚动整个列表以保持选择可见。

但是,如果选择对象以其他某种方式(例如,使用按钮)更新,则列表不会滚动。

以编程方式设置时,是否有任何方法可以强制列表滚动到新选择?

示例应用程序:

import SwiftUI

struct ContentView: View {
    @State var selection: Int? = 0

    func changeSelection(_ by: Int) {
        switch self.selection {
        case .none:
            self.selection = 0
        case .some(let sel):
            self.selection = max(min(sel + by, 20), 0)
        }
    }

    var body: some View {
        HStack {
            List((0...20), selection: $selection) {
                Text(String($0))
            }
            VStack {
                Button(action: { self.changeSelection(-1) }) {
                    Text("Move Up")
                }
                Button(action: { self.changeSelection(1) }) {
                    Text("Move Down")
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

macos swiftui

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

使用KVC分配给SEL类型的属性

ARC已启用.

我有一个类型为SEL的属性的类: @property SEL mySelector;

它是合成的: @synthesize mySelector;

然后我尝试使用KVC为它分配一个值:

SEL someSelector = @selector(doSomething:)
NSValue* someSelectorValue = [NSValue value:someSelector withObjCType:@encode(SEL)];
[target setValue:someSelectorValue forKey:@"mySelector"];
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

[<LACMyClass 0x101b04bc0> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key mySelector.
Run Code Online (Sandbox Code Playgroud)

这显然不正确 - 该类符合KVC,它只是不喜欢我传入的值.它似乎在我定义类型的属性void*而不是SEL,但这不符合我的要求.

除了用value:withObjCType:,我也试过valueWithBytes:objCType:valueWithPointer:

任何人都可以向我解释

  1. 发生了什么,和
  2. 怎么做得好?

macos cocoa objective-c

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

标签 统计

macos ×2

cocoa ×1

css ×1

html ×1

objective-c ×1

swiftui ×1