- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 iOS 应用程序中有一个 uilabel。我使用段落样式将属性文本应用于 UIlabel。但我不明白为什么前 4-5 行没有应用理由?然后开始所有打印(见下面的截图)。请提出我做错了什么。
问题
我的代码 - DetailsViewController.m
#import "DetailsViewController.h"
@interface DetailsViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelDescription;
@property (weak, nonatomic) IBOutlet UILabel *labelDetails;
@property (strong, nonatomic) NSMutableParagraphStyle *paragraphStyle;
@end
@implementation DetailsViewController
#pragma mark - lazy instantiation
- (NSMutableParagraphStyle *)paragraphStyle {
if (!_paragraphStyle) {
_paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[_paragraphStyle setAlignment:NSTextAlignmentJustified];
[_paragraphStyle setHyphenationFactor:1.0f];
[_paragraphStyle setLineSpacing:5.0f];
}
return _paragraphStyle;
}
#pragma mark - view controllers life cycle methods
- (void)viewDidLoad {
[super viewDidLoad];
[self.view layoutIfNeeded];
// updating fonts
[Utils updateLabelFontSize:self.labelDescription ForInitialHeight:20 andInitialSize:18];
[self.labelDetails setFont:[self.labelDetails.font fontWithSize:[self.labelDescription bounds].size.height * 0.85]];
// create labelText to.hFile
NSString *labelText = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [labelText length])];
[self.labelDetails setAttributedText:attributedString];
}
@end
最佳答案
试试这段代码:
NSMutableParagraphStyle *ParagraphStyle = [[NSMutableParagraphStyle alloc] init];
ParagraphStyle.alignment = NSTextAlignmentJustified;
ParagraphStyle.firstLineHeadIndent = 0.001;
ParagraphStyle.lineSpacing = 5.0;
NSAttributedString *attStr = [[NSAttributedString alloc] initWithString:labeltext attributes:@{NSParagraphStyleAttributeName:ParagraphStyle}];
self.labelDetails.AttributedText = attStr;
关于ios - 没有正确获得合理的 UILabel 属性文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40480250/
我有一个曾经是 TreeView 控件的菜单,但现在我想让每个项目更加直观,并向树中的每个对象添加更多信息。 我的第一个意图是制作一个代表项目的用户控件,并在运行时将它们添加到面板中。这是一个好方法吗
我是 Docker 新手,想知道是否有可能(并且是一个好主意)在 Docker 容器中进行开发。我的意思是创建一个容器,执行 bash,安装和配置我需要的一切,然后开始在容器内进行开发。 容器将成为我
在 Java 中: Parent obj = new Child(); 我创建了一个 Parent 类型的对象。我假设我只能调用父类中定义的方法。因此,我无法调用 Child 中定义的“附加”方法或访
注意:我省略了其他两个阶段(V 和 W)的代码,示例中不需要。 我很确定,我这样处理“开”和“关”时间的方式并不是一种有效的方式。 我想使用查找表实现“开”和“关”脉动。计时器应与表的当前选定值进行比
当代码中包含 Java instanceof 运算符时,许多人会扬起眉毛并说这是禁忌。例如,在这个 other SO Q&A ,答案说: Note that if you have to use th
我是一名优秀的程序员,十分优秀!