Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
All notable changes to this project will be documented in this file.

## Unreleased

**UILabelExtensions**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor : With a number (in this case 1).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do I need removed this spacing ??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a 1 prior to that. Like a numbering thing. But that is really cosmetic, I would suggest taking a look at writing unit tests for the same.

- `setLineSpacing(lineSpacing : CGFloat)` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/438) by *osama10*
## [Release 1.10]

### New platform added.
Expand Down Expand Up @@ -54,7 +55,7 @@ All notable changes to this project will be documented in this file.
- `validateEmail()` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/429) by *Vic-L*
- `validateDigits()` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/429) by *Vic-L*

### Deprecated/Renamed extensions
### Deprecated/Renamed extensions
1. **UIViewController**
- `public func hideKeyboardWhenTappedAround(cancelTouches: Bool = false)` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/395) by *lfarah*

Expand Down
13 changes: 13 additions & 0 deletions Sources/UILabelExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ extension UILabel {
self.text = _text
}, completion: nil)
}

// Set lineSpacing for UILabel
public func setLineSpacing(lineSpacing: CGFloat) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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!)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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))
Copy link
Collaborator

Choose a reason for hiding this comment

The 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