小编Cra*_*zed的帖子

在 SwiftUI `Text` 中使用 `NSTextAttachment`

SwiftUI 不能Text使用吗NSTextAttachment?我有这个AttributedString

var attributedString: AttributedString {
    var sampleAttributedString = AttributedString(sampleText)
    // Apply some bold and italics attributes to sampleAttributedString
     ...
    // create NSMutableAttributedString
    let mutableAttributedString = NSMutableAttributedString(sampleAttributedString)
    let image1Attachment = NSTextAttachment()
    image1Attachment.image = UIImage(named: "audio.png")
    let imageString = NSAttributedString(attachment: image1Attachment)
    mutableAttributedString.append(imageString)
    mutableAttributedString.append(NSAttributedString(string: "End of text"))

    sampleAttributedString = AttributedString(mutableAttributedString)

    return sampleAttributedString
}
Run Code Online (Sandbox Code Playgroud)

当我在 SwiftUI 视图中使用上述内容时,如下所示:

var body: some View {
    Text(attributedString)
}
Run Code Online (Sandbox Code Playgroud)

我上面嵌入的图像没有显示。所有其他文本均按预期呈现。没有catch被调用。该图像位于资产中,我也尝试过系统图像。

如果我将相同的属性字符串设置为attributedTexta 的属性,则相同的逻辑将起作用UILabel。任何帮助表示赞赏。

nsattributedstring nsmutableattributedstring swift swiftui

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

iOS MDM政策

我需要准备关于iOS移动设备管理的演示文稿.我被要求包含已实施的政策,并选择其中一个并详细描述.问题是,我不知道存在哪些不同的政策.请帮帮我.

mdm ios

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

仅保留数组中的唯一值

我有一个字符串数组.我只需保留唯一值,即.我想删除所有复制品.例如:如果数组是{string1,string1,string1,string2,string3,string3},那么最后一个数组应该是{string1,string2,string3}

for(int p = 0; p < [allNewsDates count]; p++)
    {
        NSLog(@"%@",allNewsDates[p]);
        for(int q = p+1; q < [allNewsDates count]; q++)
        {
            NSLog(@"%@   %@",allNewsDates[p],allNewsDates[q]);
            if([allNewsDates[p] isEqualToString:allNewsDates[q]])
            {
                flag = YES;
                t = q;

                break;

            }
        }
        if(flag)
        {
            //[self.date addObject:allDates[p]];


            [allNewsDates removeObjectAtIndex:p];
            NSLog(@"%i",[allNewsDates count]);
        }

        NSLog(@"%i",p);
        flag = NO;
    }
Run Code Online (Sandbox Code Playgroud)

我按照上述步骤从所有日期的数组中提取唯一日期.这通常可行.但问题是:我有一个新闻视图控制器,显示新闻提要.如果用户在那里选择任何新闻,则会将其添加到收藏夹中.如果我一次性选择所有新闻项目,那么收藏夹表格会根据日期显示新闻(不同的日期会出现在5月9日和10日),但如果我添加新闻,请转到收藏夹,然后返回新闻并点击一些新闻项目(例如5月10日)并再次访问收藏夹,然后我将在5月10日两次.我哪里错了?请帮忙!!

objective-c ios

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