我对我非常失望,但我无法将此代码从objective-c转换为swift。 : - (
是的,有人能帮帮我吗?我不知道并且发现Google没有没有。经过一段沮丧的时间后,我求求你的帮助; - )目标-c-代码:(看起来很简单[grrrrr])
-(void)setParagraphAlignment:(NSTextAlignment)newAlignment{
NSRange selectedRange = [_textView selectedRange];
NSMutableParagraphStyle *newParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[newParagraphStyle setAlignment:newAlignment];
NSDictionary *dict = @{NSParagraphStyleAttributeName: newParagraphStyle};
[textView.textStorage beginEditing];
[textView.textStorage setAttributes:dict range:selectedRange];
[textView.textStorage endEditing];
}
唯一可以改变的是: - (
textView.textStorage .beginEditing()
textView.textStorage .endEditing()
答案 0 :(得分:3)
func selectParagraphAlignment(newAlignment:NSTextAlignment) {
var selectedRange = textView.selectedRange
var newParagraphStyle = NSMutableParagraphStyle()
newParagraphStyle.alignment = newAlignment
var dict = [NSParagraphStyleAttributeName: newParagraphStyle]
textView.textStorage.beginEditing()
textView.textStorage.setAttributes(dict, range: selectedRange)
textView.textStorage.endEditing()
}
希望这会有所帮助:D