Skip to content

Commit

Permalink
Updated readme and increased version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Tudose committed Feb 26, 2019
1 parent ca533c4 commit eb94ea0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,41 @@ segmentedControl.useShadow = true

```

You can add image instead of title.

![](Resources/Image_with_attributes.png)

```swift
// ask segmented control to initialize all elements internally
segmentedControl.layoutSubviews()

let imageAttachment = NSTextAttachment()
imageAttachment.image = image
imageAttachment.bounds = CGRect(x: 0, y: -5, width: 20, height: 20)

let attributes = NSAttributedString(attachment: imageAttachment)

segmentedControl.changeAttributedTitle(attributes, selectedTile: attributes, atIndex: atIndex)
```

Or combine them.

```swift
// ask segmented control to initialize all elements internally
segmentedControl.layoutSubviews()

let imageAttachment = NSTextAttachment()
imageAttachment.image = image
imageAttachment.bounds = CGRect(x: 0, y: -5, width: 20, height: 20)

let attributes = segmentedControl.attributedDefaultTitles.first?.mutableCopy() as! NSMutableAttributedString
attributes.append(NSAttributedString(attachment: imageAttachment))

let selectedAttributes = segmentedControl.attributedSelectedTitles.first?.mutableCopy() as! NSMutableAttributedString
selectedAttributes.append(NSAttributedString(attachment: imageAttachment))

segmentedControl.changeAttributedTitle(attributes, selectedTile: selectedAttributes, atIndex: atIndex)
```
## Contribution

Feel free to Fork, submit Pull Requests or send us your feedback and suggestions!
Expand Down
Binary file added Resources/Image_with_attributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion TTSegmentedControl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ s.license = 'MIT'
s.name = "TTSegmentedControl"
s.summary = "An elegant, animated and customizable segmented control for iOS."
s.requires_arc = true
s.version = "0.4.7"
s.version = "0.4.8"
s.author = { "Igor Dumitru" => "[email protected]" }
s.homepage = "https://tapptitude.com/"
s.framework = "UIKit"
Expand Down

0 comments on commit eb94ea0

Please sign in to comment.