Skip to content

Commit

Permalink
Respect InterfaceBuilder paragraphStyle if not changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
r-plus committed Jul 5, 2016
1 parent b3b83cf commit 680cf07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Source/AttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension NSAttributedString {
- returns: The newly created NSAttributedString.
*/
public convenience init(string: String, attributes: TextAttributes) {
self.init(string: string, attributes: attributes.dictionary)
self.init(string: string, attributes: attributes.attributes)
}
}

Expand Down Expand Up @@ -75,7 +75,7 @@ extension NSMutableAttributedString {
- parameter range: The range of characters whose attributes are set.
*/
public func setAttributes(attributes: TextAttributes, range: NSRange) {
setAttributes(attributes.dictionary, range: range)
setAttributes(attributes.attributes, range: range)
}

/**
Expand Down Expand Up @@ -104,6 +104,6 @@ extension NSMutableAttributedString {
- parameter range: he range of characters to which the specified attributes apply.
*/
public func addAttributes(attributes: TextAttributes, range: NSRange) {
addAttributes(attributes.dictionary, range: range)
addAttributes(attributes.attributes, range: range)
}
}
11 changes: 10 additions & 1 deletion Source/TextAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public class TextAttributes {
return clone
}

/// InterfaceBuilder paragraph settings respected attributes dictionary.
var attributes: [String: AnyObject] {
var attributes = dictionary
if paragraphStyle == NSParagraphStyle() {
attributes[NSParagraphStyleAttributeName] = nil
}
return attributes
}

// MARK: - Font

/// The font attribute.
Expand Down Expand Up @@ -1164,4 +1173,4 @@ public class TextAttributes {
return self
}
}
#endif
#endif

0 comments on commit 680cf07

Please sign in to comment.