NSTextAlignmentCenter和NSTextAlignmentRight在NSTextTab中是错误的?
任何人都可以请检查我的东西…只是为了确保我不会生气!
我用tabStops
创build了一个NSMutableParagraphStyle
,但是他们并没有出现在我期待的地方:
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]];
然后我创build了一个方便的方法,用两个string的标签位置创build一个属性string:
- (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
上面。 当我运行代码时,插入文本,第一个string看起来居中alignment,第二个string被切掉标签的末尾:
那么我改变NSTextAlignmentRight
为NSTextAlignmentCenter
, 现在他们是正确alignment!
我知道我已经解决了我的问题,但是由于在iOS框架中似乎存在一个错误,我不希望应用程序在苹果解决此问题时中断。 所以如果有人能告诉我这是错的,还是我错了,我会非常感激,谢谢!
我自己碰到这个,可以确认截至2015年8月21日,NSTextAlignmentCenter和NSTextAlignmentRight是交换的。