Skip to content

Commit

Permalink
Merge pull request optonaut#276 from cruisediary/master
Browse files Browse the repository at this point in the history
Align README.md swift codes
  • Loading branch information
maziyarpanahi authored Sep 28, 2018
2 parents cf7818a + f1d79f9 commit bdbb2e6
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,35 @@ UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://
import ActiveLabel

let label = ActiveLabel()

label.numberOfLines = 0
label.enabledTypes = [.mention, .hashtag, .url]
label.text = "This is a post with #hashtags and a @userhandle."
label.textColor = .black
label.handleHashtagTap { hashtag in
print("Success. You just tapped the \(hashtag) hashtag")
print("Success. You just tapped the \(hashtag) hashtag")
}
```

## Custom types

```swift
let customType = ActiveType.custom(pattern: "\\swith\\b") //Regex that looks for "with"
label.enabledTypes = [.mention, .hashtag, .url, customType]
label.text = "This is a post with #hashtags and a @userhandle."

label.customColor[customType] = UIColor.purple
label.customSelectedColor[customType] = UIColor.green
let customType = ActiveType.custom(pattern: "\\swith\\b") //Regex that looks for "with"
label.enabledTypes = [.mention, .hashtag, .url, customType]
label.text = "This is a post with #hashtags and a @userhandle."
label.customColor[customType] = UIColor.purple
label.customSelectedColor[customType] = UIColor.green

label.handleCustomTap(for: customType) { element in
print("Custom type tapped: \(element)")
}
label.handleCustomTap(for: customType) { element in
print("Custom type tapped: \(element)")
}
```

## Enable/disable highlighting

By default, an ActiveLabel instance has the following configuration

```swift
label.enabledTypes = [.mention, .hashtag, .url]
label.enabledTypes = [.mention, .hashtag, .url]
```

But feel free to enable/disable to fit your requirements
Expand All @@ -66,27 +64,24 @@ When using `customize(block:)`, you can group all the customizations on the labe
Example:

```swift

label.customize { label in
label.text = "This is a post with #multiple #hashtags and a @userhandle."
label.textColor = UIColor(red: 102.0/255, green: 117.0/255, blue: 127.0/255, alpha: 1)
label.hashtagColor = UIColor(red: 85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1)
label.mentionColor = UIColor(red: 238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1)
label.URLColor = UIColor(red: 85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1)
label.handleMentionTap { self.alert("Mention", message: $0) }
label.handleHashtagTap { self.alert("Hashtag", message: $0) }
label.handleURLTap { self.alert("URL", message: $0.absoluteString) }
}


label.customize { label in
label.text = "This is a post with #multiple #hashtags and a @userhandle."
label.textColor = UIColor(red: 102.0/255, green: 117.0/255, blue: 127.0/255, alpha: 1)
label.hashtagColor = UIColor(red: 85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1)
label.mentionColor = UIColor(red: 238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1)
label.URLColor = UIColor(red: 85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1)
label.handleMentionTap { self.alert("Mention", message: $0) }
label.handleHashtagTap { self.alert("Hashtag", message: $0) }
label.handleURLTap { self.alert("URL", message: $0.absoluteString) }
}
```

## Trim long urls

You have the possiblity to set the maximum lenght a url can have;

```
label.urlMaximumLength = 30
```swift
label.urlMaximumLength = 30
```

From now on, a url that's bigger than that, will be trimmed.
Expand All @@ -101,8 +96,8 @@ From now on, a url that's bigger than that, will be trimmed.
##### `hashtagSelectedColor: UIColor?`
##### `URLColor: UIColor = .blueColor()`
##### `URLSelectedColor: UIColor?`
#### `customColor: [ActiveType : UIColor]`
#### `customSelectedColor: [ActiveType : UIColor]`
##### `customColor: [ActiveType : UIColor]`
##### `customSelectedColor: [ActiveType : UIColor]`
##### `lineSpacing: Float?`

##### `handleMentionTap: (String) -> ()`
Expand Down

0 comments on commit bdbb2e6

Please sign in to comment.