问题描述
任何人都可以帮我检查一下...只是为了确保我不会生气!
Can anyone please check something for me... Just to make sure I'm not going mad!
我用tabStops
创建了一个NSMutableParagraphStyle
,但是它们没有出现在我期望的位置:
I created an NSMutableParagraphStyle
with tabStops
, but they weren't appearing where I was expecting:
float width = self.myLabel.frame.size.width;
self.tabStyle.tabStops = @[[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width - 50 options:nil],
[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width options:nil]];
然后,我创建了一个方便的方法来创建带有两个字符串的制表符位置的属性字符串:
Then I created a convenience method to create an attributed string with the tab positions for two strings:
- (NSAttributedString *)tabbedTextWithFirstString:(NSString *)firstString secondString:(NSString *)secondString
{
NSDictionary *attributes = @{NSFontAttributeName:[UIFont fontWithName:kHSTFontFaceDefault size:14.0]};
NSString *tabbedStr = [NSString stringWithFormat:@"\t%@\t", firstString];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:tabbedStr attributes:attributes];
attributes = @{NSFontAttributeName:[UIFont fontWithName:kHSTFontFaceDefaultBold size:14.0]};
[attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:secondString attributes:attributes]];
[attrStr addAttribute:NSParagraphStyleAttributeName value:self.tabStyle range:NSMakeRange(0, attrStr.length)];
return attrStr;
}
这被应用于两个单独的UILabel
,一个出现在另一个之上.当我运行代码时,插入文本,第一个字符串看上去居中对齐,第二个字符串被切掉了标签的末尾:
This was being applied to two separate UILabel
s that appear one on top of the other. When I ran the code, inserting the text, the first string looked center aligned, and the second string was being cut off the end of the label:
因此,然后我将NSTextAlignmentRight
更改为NSTextAlignmentCenter
,并且现在它们已正确对齐!
So then I changed NSTextAlignmentRight
for NSTextAlignmentCenter
, and now they are right aligned correctly!
我知道我已经解决了我的问题,但是由于iOS框架中似乎有一个错误,因此我不希望该应用程序在Apple修复此问题时中断.因此,如果有人可以告诉我这是否确实是错的,或者如果我真的误会了,我将非常感谢,谢谢!
I know I have solved my issue, but since there appears to be a mistake in the iOS framework, I don't want the app to break if and when Apple fix this issue. So if anyone could tell me if it is indeed wrong, or if I am actually mistaken, I'd be very grateful, thanks!
推荐答案
我自己遇到了这个问题,可以确认截至2015年8月21日,NSTextAlignmentCenter和NSTextAlignmentRight已互换.
I just ran into this myself and can confirm that as of Aug. 21, 2015 NSTextAlignmentCenter and NSTextAlignmentRight are swapped.
这篇关于NSTextTab中的NSTextAlignmentCenter和NSTextAlignmentRight是错误的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!