We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View 设置成UISemanticContentAttributeForceRightToLeft布局的时候,YYLabel 通过<Masonry/Masonry.h>设置约束的时候,不能像UISemanticContentAttributeForceLeftToRight布局的时候,不设置宽度约束的时候,宽度根据内容自动撑。请问是不支持UISemanticContentAttributeForceRightToLeft?如果支持请问该怎么设置约束,宽度按照内容自动设置。 案例如下:
#import "ESDViewController.h" #import <Masonry/Masonry.h> #import <YYText/YYText.h> @implementation ESDViewController - (void)viewDidLoad { [super viewDidLoad]; [self testRightToLeft]; } - (void)testRightToLeft{ // 设置视图的整体语义方向 self.view.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; YYLabel *label = [[YYLabel alloc] init]; label.numberOfLines = 0; label.backgroundColor = [UIColor lightGrayColor]; label.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; label.textAlignment = NSTextAlignmentRight; // 配置文本属性 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.alignment = NSTextAlignmentRight; paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft; NSDictionary *attributes = @{ NSFontAttributeName: [UIFont systemFontOfSize:16], NSParagraphStyleAttributeName: paragraphStyle, NSForegroundColorAttributeName: [UIColor blackColor] }; NSString *text = @"testRightToLeft"; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:attributes]; label.attributedText = attributedText; // 将 label 添加到视图中 [self.view addSubview:label]; // 使用 Masonry 设置宽度和位置约束 [label mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(100); make.leading.equalTo(self.view.mas_leading).offset(10); make.trailing.lessThanOrEqualTo(self.view.mas_trailing).offset(-20); //尾部 }]; } - (void)testLeftToRight{ // 设置视图的整体语义方向 self.view.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; YYLabel *label = [[YYLabel alloc] init]; label.numberOfLines = 0; label.backgroundColor = [UIColor lightGrayColor]; label.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; label.textAlignment = NSTextAlignmentLeft; // 配置文本属性 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.alignment = NSTextAlignmentLeft; paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight; NSDictionary *attributes = @{ NSFontAttributeName: [UIFont systemFontOfSize:16], NSParagraphStyleAttributeName: paragraphStyle, NSForegroundColorAttributeName: [UIColor blackColor] }; NSString *text = @"testLeftToRight"; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:attributes]; label.attributedText = attributedText; // 将 label 添加到视图中 [self.view addSubview:label]; // 使用 Masonry 设置宽度和位置约束 [label mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(150); make.leading.equalTo(self.view.mas_leading).offset(10); make.trailing.lessThanOrEqualTo(self.view.mas_trailing).offset(-20); //尾部 }]; } @end
效果图: testRightToLeft: testRightToLeft宽度不对,没有按照内容自动计算
testLeftToRight:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
View 设置成UISemanticContentAttributeForceRightToLeft布局的时候,YYLabel 通过<Masonry/Masonry.h>设置约束的时候,不能像UISemanticContentAttributeForceLeftToRight布局的时候,不设置宽度约束的时候,宽度根据内容自动撑。请问是不支持UISemanticContentAttributeForceRightToLeft?如果支持请问该怎么设置约束,宽度按照内容自动设置。
案例如下:
效果图:
testRightToLeft:
testRightToLeft宽度不对,没有按照内容自动计算
testLeftToRight:
The text was updated successfully, but these errors were encountered: