• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NSAttributedString Additions that add convenience methods to manipulate attributed strings easily

OHAttributedStringAdditions

Version Platform Build Status

This pod contains categories on NSAttributedString to add a lot of very useful convenience methods to manipulate attributed strings.

Convenience methods include:

  • font manipulation (setFont:range: and fontAtIndex:effectiveRange:)
  • text color (setTextColor:range: and textColorAtIndex:effectiveRange:)
  • background color
  • bold, italics and underline styles
  • add URLs to your text
  • paragraph styles (indentation, line spacing, …)
  • baseline adjustment, subscript, superscript, …
  • And much more

It also contains:

  • A category on UIFont to build a font given its postscript name and derive a bold/italic font from a standard one and vice-versa.
  • A category on UILabel to make it easier to detect the character at a given coordinate, which is useful to detect if the user tapped on a link (if the character as a given tapped CGPoint has an associated NSURL) and similar stuff

Note that for advanced URL detection, you should still prefer UITextView (configuring it with editable=NO) and its dedicated delegate methods instead of using UILabel (which does not publicly expose its NSLayoutManager to properly compute the exact way its characters are laid out, forcing us to recreate the TextKit objects ourselves, contrary to UITextView).

Documentation

The source code is fully commented and documentation is auto-generated here.

There is also some help pages in the repository's wiki.

Installation

The suggested installation is via CocoaPods. Simply add the following line to your Podfile:

pod 'OHAttributedStringAdditions'

Then do a pod install.

Example

A demo project is provided in the repository. Don't hesitate to open Example/AttributedStringDemo.xcworkspace and play with it.

If you have CocoaPods, you can even try that Sample project even if you don't have cloned the project yet, by using pod try OHAttributedStringAdditions in your terminal.

Demo Capture

Future improvements

  • Improving documentation on edge cases, like documenting the behavior about when some attribute is not present or if we are allowed to pass nil to arguments.
  • Adding support for OSX. This should only need little adjustments, like getting rid of the #import <UIKit/UIKit.h> in the pch file, or replacing UIColor and UIFont classes with NSColor and NSFont (using macros to switch from one to another depending on the SDK), but that still requires some work and tests.

Note: The original code of these categories comes from my old OHAttributedLabel pod, which is now deprecated as I don't have time to maintain it. As this previous implementation was based on CoreText and was not compatible (sometimes even crash) with UIKit/TextKit, I converted those categories to create this UIKit-compliant NSAttributedString, not related to CoreText and OHAttributedLabel anymore and that now work with latest versions of iOS/UIKit/TextKit.

Licence

This component is under the MIT Licence (See the LICENSE file).

More Repositories

1

OHHTTPStubs

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Objective-C
5,039
star
2

Reusable

A Swift mixin for reusing views easily and in a type-safe way (UITableViewCells, UICollectionViewCells, custom UIViews, ViewControllers, Storyboards…)
Swift
2,999
star
3

OHAttributedLabel

UILabel that supports NSAttributedString
Objective-C
1,511
star
4

Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
Swift
977
star
5

UIImage-Resize

Category to add some resizing methods to the UIImage class, to resize it to a given CGSize — or fit in a CGSize keeping aspect ratio
Objective-C
352
star
6

OHAutoNIBi18n

Automate the Localization/Translation of your XIB & interface without any additional code nor IBOutlet!
Objective-C
120
star
7

SourceryTemplates

Some templates to use for Code Generation in Swift with http://github.com/krzysztofzablocki/Sourcery
HTML
99
star
8

OHGridView

View that display cells as a grid. Uses quite the same API as UITableView
Objective-C
71
star
9

OHPDFImage

A library to easily load PDF files as UIImages
Objective-C
56
star
10

Dip-UI

UI Extensions for https://github.com/AliSoftware/Dip
Swift
48
star
11

OHSwipeWheel

A widget to choose between multiple values by swiping an horizontal wheel. This is kinda like a UIPickerView but rolling horizontally and that takes much less space
Objective-C
42
star
12

pprof

Ruby Gem to list, filter, search and print Provisioning Profiles files
Ruby
39
star
13

Xcode-Utils

A set of useful templates, macros, etc. to use with the Apple Developer Tools
Objective-C
32
star
14

OpeningHours

A small iOS app to keep the list of Opening Hours for your local shops you're used to go to
Swift
27
star
15

OHActionSheet

UIActionSheet subclass that uses blocks to handle its callback (which make the code much more easier and readable)
Objective-C
27
star
16

OHStackView

This class automatically stack its subviews and relayout them when one of them change its size.
Objective-C
25
star
17

OHAlertView-OHActionSheet

This repo is obsolete. Use OHAlertView and OHActionSheet repos now.
Objective-C
21
star
18

OHURLLoader

Class that uses blocks (new to iOS4/OSX 10.6) to make URL requests/downloads much more easier
Objective-C
19
star
19

OHAlertView

UIAlertView subclass that uses blocks to handle its callback (which make the code much more easier and readable)
Objective-C
16
star
20

AliJSONRPC

A JSON-RPC Framework for Cocoa. Supports JSON-RPC 1.0, 1.1 and 2.0
Objective-C
13
star
21

alisoftware.github.io

AliSoftware's Blog "Crunchy Development": making Swift Magic ✨
SCSS
12
star
22

generate-enum-allvalues

Automatically generate a `static let allValues` for your Swift enums
Swift
8
star
23

SWPromisesDemo

A demo project implementing the StarWars API (swapi.co) in Swift with PromiseKit
Swift
8
star
24

FunctionalVCDemo

Demo for the Functional ViewControllers concept in RxSwift
Swift
8
star
25

MagicSwiftNoStrings

Demo project demonstrate some nice patterns to get rid of String-based API using enums, mixins and SwiftGen
Swift
8
star
26

CodeGen-Workshop

This is the repository used for my SwiftAveiro'19 Workshop about Code Generation
Swift
6
star
27

FormWorkflow

A sample project to demonstrate how to use Promises to describe a workflow of Screens/ViewControllers
Swift
6
star
28

ObjcSwitch

A category to allow you to use the "switch/case"-like syntax with NSObjects (and not just integers/enums!)
Objective-C
6
star
29

swift-syntax-linter-demo

A demo project on how to use SwiftSyntax to implement a simple linter detecting specific call sites of a function in your source code
Swift
6
star
30

KeyPathObserver

Execute blocks when a given property changes (this is KVO, the block-style way)
Objective-C
5
star
31

talks

My talks at conferences
5
star
32

CodeGenDemo

Demo project to show the advantages of Code Generation with SwiftGen & Sourcery
Swift
4
star
33

AliSoftware

3
star
34

SwiftDependencyInjectionTest

A test project to play around and explore some Dependency Injection ideas in Swift — This was the POC that led to Dip
Swift
3
star
35

banana-crumb-muffins

This is the recipe for Banana Crumb Muffins, presented as a GitHub repository (one commit for each step of the recipe). Just for fun.
2
star
36

TVShowOrganizer

Ruby
2
star
37

XCAssetsSample

This sample project try to expose a complex case of using multiple assets with multiple targets. Originally created to test CocoaPods/CocoaPods#3263
Objective-C
2
star
38

xcodeplugin

Tools to generate dvtplugin / xcodeplugins especially for PLIST-files structure definitions
Shell
2
star