gpt4 book ai didi

ios - 没有正确获得合理的 UILabel 属性文本

转载 作者:行者123 更新时间:2023-11-29 00:36:28 25 4
gpt4 key购买 nike

我的 iOS 应用程序中有一个 uilabel。我使用段落样式将属性文本应用于 UIlabel。但我不明白为什么前 4-5 行没有应用理由?然后开始所有打印(见下面的截图)。请提出我做错了什么。

问题

enter image description here

我的代码 - 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com