2016-09-03 6 views
0

私は半日でHow to disable word-wrap of NSTextView? に答えを試しましたが、運がなかった。答えはちょっと散らかっていて、本当に混乱していました。NSTextViewのワードラップを無効にできません

私はこのコードを持っている:

@IBOutlet var display: NSTextView! 

func applicationDidFinishLaunching(aNotification: NSNotification) { 
    // Insert code here to initialize your application 
    let LargeNumberForText: CGFloat = 1.0e7 
    display.textContainer!.containerSize = NSMakeSize(LargeNumberForText, LargeNumberForText) 
    display.textContainer!.widthTracksTextView = false 
    display.horizontallyResizable = true 
    display.autoresizingMask = [.ViewWidthSizable, .ViewHeightSizable] 
} 

を、私は.xibでこれを持っている: NSTextView size settings

私はステップを逃しましたか?

答えて

0

私の問題は、実際Premature line wrapping in NSTextView when tabs are usedに私は上記ワードラップコードの両方を使用して、テキストを変更した後、これを呼び出すことによって、問題を修正しました:

displayはNSTextViewある
func format() { 
    let numStops = 100000; 
    let tabInterval = 40; 
    var tabStop: NSTextTab 

    //attributes for attributed String of TextView 

    let paraStyle = NSMutableParagraphStyle() 

    // This first clears all tab stops, then adds tab stops, at desired intervals... 
    paraStyle.tabStops = [] 
    for cnt in 1...numStops { 
     tabStop = NSTextTab(type: .LeftTabStopType, location: CGFloat(tabInterval * cnt)) 
     paraStyle.addTabStop(tabStop) 
    } 

    var attrs = [String: AnyObject]() 
    attrs.updateValue(paraStyle, forKey:NSParagraphStyleAttributeName) 

    display.textStorage!.addAttributes(attrs, range: NSMakeRange(0, display.textStorage!.string.characters.count)) 
} 

。サブクラス化は、もちろんよりエレガントになります。

関連する問題