小编And*_*w H的帖子

最后一行NSAttributedString未在UILabel中呈现

我有文本,其中包含我试图在视图上呈现的HTML格式.目前我正在使用一个NSAtributedString来显示一个文本UILabel.

我获得了如下的属性字符串:

NSString *htmlString = @"<html>"
    "  <head>"
    "    <style type='text/css'>"
    "      body { font: 12pt 'Helvetica'; color: #111111; }"
    "    </style>"
    "  </head>"
    "  <body>";
    htmlString = [htmlString stringByAppendingString:self.descriptionText];
    htmlString = [htmlString stringByAppendingString:@"</body></html>"];

    NSError *err = nil;
    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithData: [htmlString dataUsingEncoding:NSUTF8StringEncoding]
                                                                          options: @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
                                                               documentAttributes: nil
                                                                            error: &err];
Run Code Online (Sandbox Code Playgroud)

然后将其分配给我的标签attributedText属性.self.descriptionText属性NSString可以包含简单的HTML标记,例如带有内联样式的p标记或span标记.在另一个StackOverflow帖子中找到了将字符串包装在HTML文档中的技术.

UILabel被设定为行= 0和换行符=自动换行.我看到的行为是标签正确生长以容纳整个字符串,但无论字符串有多长,字符串的最后一行都不会呈现.

这是一个带有两个标签的屏幕截图.顶部标签(带黄色背景)中包含我的HTML属性字符串.您可以看到标签的大小适合允许3行文本,但只有两行被渲染,其余的被截断.第二个标签(带有红色背景)已经为其Text属性分配了一个纯字符串,它绘制得很好.

示例图像中使用的HTML字符串包含以下文本:

<p>With the world&#39;s longest fan-vaulted ceiling, an original …
Run Code Online (Sandbox Code Playgroud)

html objective-c nsattributedstring uilabel ios

8
推荐指数
2
解决办法
2658
查看次数

在JUnit测试中将Maven属性传递给Spring Application上下文文件

我试图让JUnit测试用于项目,但是我无法从pom中获取注入应用程序上下文xml文件的属性.具体来说,我想注入env.code变量,该变量定义运行应用程序的环境.

就目前而言,pom包含

<properties>
    <env.code>dev</env.code>
    ...
</properties>
Run Code Online (Sandbox Code Playgroud)

当应用程序正常运行时,web.xml文件将获取env.code变量并将其重命名为"environment"."environment"变量在引用的上下文配置xml文件中使用.

<context-param>
    <param-name>environment</param-name>
    <param-value>${env.code}</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:SpringBeans.xml classpath:SpringDataSource.xml</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

我想在JUnit测试中复制此行为.到目前为止,我的简单测试用例看起来像

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/SpringBeans.xml", "/SpringDataSource.xml"})
public class MyTest {

    @Test
    public void testOne() {}

}
Run Code Online (Sandbox Code Playgroud)

由于我没有运行Web应用程序,因此绕过web.xml文件,因为解析应用程序上下文xml文件时出现问题,因此尝试运行测试时出错,因为$ {environment}未被替换.

如何将pom中定义的env.code值注入到应用程序上下文文件的$ {environment}占位符中?

java junit spring maven

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

标签 统计

html ×1

ios ×1

java ×1

junit ×1

maven ×1

nsattributedstring ×1

objective-c ×1

spring ×1

uilabel ×1