-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extension of UIlabel for adding line spacing with the method of n… #438
base: master
Are you sure you want to change the base?
Changes from 4 commits
cd810e5
6a55e8f
f949239
d4b9474
2d20dac
d59ca01
c4d58e0
638c472
61f701b
e5f55c5
c00d920
277316f
fac501a
13b1dcc
f3047f8
e736d02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,19 @@ extension UILabel { | |
self.text = _text | ||
}, completion: nil) | ||
} | ||
|
||
// Set lineSpacing for UILabel | ||
public func setLineSpacing(lineSpacing: CGFloat) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to write a unit test for this ? |
||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.lineSpacing = 1.0 | ||
paragraphStyle.lineHeightMultiple = lineSpacing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is confusing. Does this mean your spacing = 1.0 * lineHeight = lineSpacing. If so, you could just call the method arg as lineHeightMultiple. |
||
paragraphStyle.alignment = self.textAlignment | ||
|
||
let attrString = NSMutableAttributedString(string: self.text!) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could actually live as its own var. Otherwise its unnecessary allocation of the attr string per call. |
||
attrString.addAttribute(NSFontAttributeName, value: self.font, range: NSMakeRange(0, attrString.length)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NSMakeRange is repeated, you can abstract that away as a single call. |
||
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length)) | ||
self.attributedText = attrString | ||
} | ||
} | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erm not under v1.10. Under unreleased. V 1.10 is already released as a pod.