Skip to content

Commit 1cab205

Browse files
Initializer methods added and Update of LICENSE & README.md files
1 parent e23420a commit 1cab205

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

Example/KWTextStyleLabel/Base.lproj/Main.storyboard

+3-23
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="m8j-GV-ibK">
2525
<rect key="frame" x="28" y="46" width="320" height="575"/>
2626
<subviews>
27-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="justified" lineBreakMode="characterWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tBY-1B-pbW" customClass="KWTextStyleLabel" customModule="KWTextStyleLabel">
27+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="justified" lineBreakMode="characterWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tBY-1B-pbW" userLabel="bodyLabel" customClass="KWTextStyleLabel" customModule="KWTextStyleLabel">
2828
<rect key="frame" x="8" y="142" width="296" height="433"/>
2929
<constraints>
3030
<constraint firstAttribute="height" constant="433" id="Zjq-e0-ceZ"/>
@@ -47,35 +47,14 @@ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
4747
</userDefinedRuntimeAttribute>
4848
</userDefinedRuntimeAttributes>
4949
</label>
50-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="characterWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ICB-6o-zxg" customClass="KWTextStyleLabel" customModule="KWTextStyleLabel">
51-
<rect key="frame" x="8" y="0.0" width="296" height="122"/>
52-
<constraints>
53-
<constraint firstAttribute="height" constant="122" id="gpa-Oo-MND"/>
54-
</constraints>
55-
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
56-
<nil key="textColor"/>
57-
<nil key="highlightedColor"/>
58-
<userDefinedRuntimeAttributes>
59-
<userDefinedRuntimeAttribute type="number" keyPath="lineGap">
60-
<real key="value" value="25"/>
61-
</userDefinedRuntimeAttribute>
62-
<userDefinedRuntimeAttribute type="number" keyPath="characterSpacing">
63-
<real key="value" value="5"/>
64-
</userDefinedRuntimeAttribute>
65-
<userDefinedRuntimeAttribute type="string" keyPath="kerningText" value="Heading with Character spacing: 5 and Line spacing: 25"/>
66-
</userDefinedRuntimeAttributes>
67-
</label>
6850
</subviews>
6951
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
7052
<constraints>
7153
<constraint firstAttribute="trailing" secondItem="tBY-1B-pbW" secondAttribute="trailing" constant="16" id="0sC-cU-038"/>
7254
<constraint firstAttribute="bottom" secondItem="tBY-1B-pbW" secondAttribute="bottom" id="9EN-r2-UJb"/>
7355
<constraint firstItem="tBY-1B-pbW" firstAttribute="leading" secondItem="m8j-GV-ibK" secondAttribute="leading" constant="8" id="Ah3-71-KWg"/>
74-
<constraint firstItem="ICB-6o-zxg" firstAttribute="leading" secondItem="m8j-GV-ibK" secondAttribute="leading" constant="8" id="PHb-2B-yaY"/>
75-
<constraint firstItem="ICB-6o-zxg" firstAttribute="top" secondItem="m8j-GV-ibK" secondAttribute="top" id="Tjj-rl-9Lc"/>
7656
<constraint firstAttribute="width" constant="320" id="UhG-RF-fGP"/>
7757
<constraint firstAttribute="height" constant="575" id="fdB-uY-dIL"/>
78-
<constraint firstAttribute="trailing" secondItem="ICB-6o-zxg" secondAttribute="trailing" constant="16" id="jcn-TF-c1I"/>
7958
</constraints>
8059
</view>
8160
</subviews>
@@ -86,7 +65,8 @@ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
8665
</constraints>
8766
</view>
8867
<connections>
89-
<outlet property="test" destination="tBY-1B-pbW" id="jut-7g-3Mi"/>
68+
<outlet property="bodyLabel" destination="tBY-1B-pbW" id="hPj-t9-1oj"/>
69+
<outlet property="subView" destination="m8j-GV-ibK" id="J14-Tt-leA"/>
9070
</connections>
9171
</viewController>
9272
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>

Example/KWTextStyleLabel/ViewController.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ import KWTextStyleLabel
1212
class ViewController: UIViewController {
1313

1414
// MARK: - IBOutlets
15-
@IBOutlet weak var test: KWTextStyleLabel!
15+
@IBOutlet weak var bodyLabel: KWTextStyleLabel!
16+
@IBOutlet weak var subView: UIView!
1617

1718
// MARK: - Lifecycle
1819
override func viewDidLoad() {
1920
super.viewDidLoad()
2021

21-
test.characterSpacing = 3
22-
test.lineGap = 10
23-
test.text = "Body with\nCharacter spacing: 3\nand Line spacing: 10\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
22+
let headingLabel = KWTextStyleLabel(characterSpacing: 5, lineGap: 25, text: "Heading with Character spacing: 5 and Line spacing: 25")
23+
headingLabel.frame = CGRect(x: 8, y: 0, width: 296, height: 122)
24+
headingLabel.numberOfLines = 0
25+
headingLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.headline)
26+
headingLabel.textAlignment = NSTextAlignment.center
27+
subView.addSubview(headingLabel)
28+
29+
bodyLabel.characterSpacing = 3
30+
bodyLabel.lineGap = 10
31+
bodyLabel.text = "Body with\nCharacter spacing: 3\nand Line spacing: 10\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
2432
}
2533
}

KWTextStyleLabel/Classes/KWTextStyleLabel.swift

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import UIKit
1010

1111
@IBDesignable open class KWTextStyleLabel: UILabel {
1212

13+
// MARK: - Convenience Initializer
14+
public convenience init(characterSpacing: CGFloat = 0, lineGap: CGFloat = 0, text: String = "") {
15+
self.init()
16+
17+
self.characterSpacing = characterSpacing
18+
self.lineGap = lineGap
19+
self.text = text
20+
}
21+
1322
// MARK: - IBInspectables
1423
@IBInspectable open var characterSpacing: CGFloat = 0 {
1524
didSet {

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017 Vinoth Anandan <[email protected]>
1+
Copyright (c) 2017 KeepWorks Technologies Pvt Ltd. All rights reserved.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<img src="ScreenShots/screenshot.png" width="187" height="333">
44

5+
[![Build Status](https://www.bitrise.io/app/7af1764622c959f9.svg?token=7AABrQmoi2QwsCO-5rj4ww)](https://www.bitrise.io/app/7af1764622c959f9)
56
[![Version](https://img.shields.io/cocoapods/v/KWTextStyleLabel.svg?style=flat)](http://cocoapods.org/pods/KWTextStyleLabel)
67
[![License](https://img.shields.io/cocoapods/l/KWTextStyleLabel.svg?style=flat)](http://cocoapods.org/pods/KWTextStyleLabel)
78
[![Platform](https://img.shields.io/cocoapods/p/KWTextStyleLabel.svg?style=flat)](http://cocoapods.org/pods/KWTextStyleLabel)
@@ -42,6 +43,25 @@ label.characterSpacing = 3
4243
label.lineGap = 10
4344
label.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
4445
```
46+
#### Can create label with KWTextStyleLabel initializer
47+
48+
```swift
49+
let label = KWTextStyleLabel(characterSpacing: 5, lineGap: 25, text: "Lorem Ipsum")
50+
label.frame = CGRect(x: 8, y: 0, width: 296, height: 122)
51+
view.addSubview(label)
52+
```
53+
54+
#### KWTextStyleLabel initializer have 3 different optional parameters
55+
56+
```swift
57+
KWTextStyleLabel()
58+
KWTextStyleLabel(characterSpacing: <CGFloat>)
59+
KWTextStyleLabel(lineGap: <CGFloat>)
60+
KWTextStyleLabel(text: <String>)
61+
KWTextStyleLabel(characterSpacing: <CGFloat>, lineGap: <CGFloat>)
62+
KWTextStyleLabel(lineGap: <CGFloat>, text: <String>)
63+
KWTextStyleLabel(characterSpacing: <CGFloat>, text: <String>)
64+
```
4565

4666
## Author
4767

@@ -59,4 +79,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/keepwo
5979

6080
## License
6181

62-
KWTextStyleLabel is available under the [MIT License](http://opensource.org/licenses/MIT). See the LICENSE file for more info.
82+
KWTextStyleLabel is available under the [MIT License](http://opensource.org/licenses/MIT). See the [License](https://github.com/keepworks/KWTextStyleLabel/blob/master/LICENSE) file for more info.

0 commit comments

Comments
 (0)