All Projects → loopeer → AttributedStringWrapper

loopeer / AttributedStringWrapper

Licence: MIT license
a simple packaging for NSAttributedString to make the developers easy to use

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to AttributedStringWrapper

Swiftyattributes
A Swifty API for attributed strings
Stars: ✭ 1,303 (+8043.75%)
Mutual labels:  cocoa, nsattributedstring
CuteAttribute
An elegant way to deal with attributed string in swift.
Stars: ✭ 65 (+306.25%)
Mutual labels:  nsattributedstring, nsmutableattributedstring
Widgetkit
Compose native apps without a code using JSON and load them as NSBundle into another app dynamicly from local or remote locations.
Stars: ✭ 191 (+1093.75%)
Mutual labels:  cocoa
objc-lisp-bridge
A portable reader and bridge for interacting with Objective-C and Cocoa
Stars: ✭ 39 (+143.75%)
Mutual labels:  cocoa
Criollo
A powerful Cocoa web framework and HTTP server for macOS, iOS and tvOS.
Stars: ✭ 229 (+1331.25%)
Mutual labels:  cocoa
Cocoatextfield
Apple TextField created according to the Material.IO guidelines of 2019. Featured at Medium.
Stars: ✭ 195 (+1118.75%)
Mutual labels:  cocoa
react-native-macos
Fork of https://github.com/ptmt/react-native-macos with more features
Stars: ✭ 22 (+37.5%)
Mutual labels:  cocoa
Wwdc Notes
WWDCNotes.com content ✨
Stars: ✭ 183 (+1043.75%)
Mutual labels:  cocoa
trace-cocoa-sdk
Catch bugs before they reach production — get detailed crash reports and monitor how your app is performing across the entire install base.
Stars: ✭ 15 (-6.25%)
Mutual labels:  cocoa
Carthage
A simple, decentralized dependency manager for Cocoa
Stars: ✭ 14,487 (+90443.75%)
Mutual labels:  cocoa
OutlineViewDiffableDataSource
Stop looking for NSOutlineViewDiffableDataSource, it’s here 👌
Stars: ✭ 96 (+500%)
Mutual labels:  cocoa
Cacao
Rust bindings for AppKit (macOS) and UIKit (iOS/tvOS). Experimental, but working!
Stars: ✭ 205 (+1181.25%)
Mutual labels:  cocoa
Dd Plist
A java library providing support for ASCII, XML and binary property lists.
Stars: ✭ 201 (+1156.25%)
Mutual labels:  cocoa
panthro
An implementation of XPath 3.0 in Objective-C/Cocoa
Stars: ✭ 45 (+181.25%)
Mutual labels:  cocoa
Cocoa Rest Client
A free, native Apple macOS app for testing HTTP/REST endpoints
Stars: ✭ 2,257 (+14006.25%)
Mutual labels:  cocoa
WCSDateRange
Simple date range class.
Stars: ✭ 13 (-18.75%)
Mutual labels:  cocoa
Twitterx
Keeping Twitter for macOS alive with code injection
Stars: ✭ 187 (+1068.75%)
Mutual labels:  cocoa
Textmate
TextMate is a graphical text editor for macOS 10.12 or later
Stars: ✭ 13,729 (+85706.25%)
Mutual labels:  cocoa
Punic
Clean room reimplementation of Carthage tool
Stars: ✭ 236 (+1375%)
Mutual labels:  cocoa
WWDCNotes
WWDCNotes.com content
Stars: ✭ 343 (+2043.75%)
Mutual labels:  cocoa

AttributedStringWrapper

AttributedStringWrapper

Xcode 8.3+ iOS 8.0+ Swift 3.1+ Version Carthage compatible

AttributedStringWrapper is a simple packaging for NSAttributedString to make the developers easy to use 

Overview

AttributedStringWrapper is base on String extension, converted into RawRepresentable protocal in order to solve the question of Objective-C namespace. So it looks a bit strange, if you have a better way, please contact me

Before, you may like me

extension UILabel {
    convenience init(frame: CGRect = .zero, attributedText: String, textColor: UIColor, font: UIFont, lineSpacing: CGFloat) {
        self.init(frame: frame)
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = lineSpacing
        paragraphStyle.lineBreakMode = .byTruncatingTail
        let attrStr = NSAttributedString(string: attributedText, attributes: [NSParagraphStyleAttributeName: paragraphStyle,
                                                                              NSFontAttributeName: font,
                                                                              NSForegroundColorAttributeName: textColor])
        self.attributedText = attrStr
    }
}
        let attr = NSMutableAttributedString(string: content)
        let paragrap = NSParagraphStyle()
        paragrap.lineSpacing = 8.0
        paragrap.alignment = .center
        attr.addAttributes([NSParagraphStyle: paragrap], range: NSMakeRange(0, attr.length))
        attr.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 17)], range: NSMakeRange(0, attr.length))
        let shadow = NSShadow()
        shadow.shadowColor = UIColor.red
        shadow.shadowOffset = CGSize(width: 3, height: 3)
        shadow.shadowBlurRadius = 2.0
        attr.addAttributes([NSShadowAttributeName: NSShadow], range: NSMakeRange(0, attr.length))
        label6.attributedText = attr

After:

// 1. shadow: you can set range, default allRange
label1.attributedText = content.toAttributed.shadow {
    $0.shadowColor = UIColor.red
    $0.shadowOffset = CGSize(width: 3, height: 3)
    $0.shadowBlurRadius = 2.0
}.rawValue


// 2. paragraphStyle: you can set range, default allRange

let attrText2 = content.toAttributed.paragraph {
    $0.alignment = .center
    $0.lineSpacing = 8.0
}.font(UIFont.systemFont(ofSize: 15))

label2.attributedText = attrText2.rawValue
print(attrText2.getHeight(by: screenW - 20))


// 3. underLine:  you can set range, default allRange
label3.attributedText = content.toAttributed.underLine(style: [.styleDouble, .patternDot], color: UIColor.red).rawValue

// 4. font, foregroundColor
textField.attributedPlaceholder = "Please enter the phone number".toAttributed.font(.systemFont(ofSize: 15))
                                                                 .foregroundColor(.red).rawValue

// 5. Even you can do it
label6.attributedText = content.toAttributed
            .underLine(style: [.styleSingle, .patternDot], color: .red, range: NSMakeRange(0, 5))
            .font(.systemFont(ofSize: 18), range: NSMakeRange(5, 5))
            .backgroundColor(.blue, range: NSMakeRange(10, 5))
            .foregroundColor(.purple, range: NSMakeRange(15, 5))
            .baselineOffset(value: 5, range: NSMakeRange(20, 5))
            .obliqueness(angle: 0.5, range: NSMakeRange(25, 5))
            .kern(padding: 0.3, range: NSMakeRange(30, 5))
            .expansion(value: 0.3, range: NSMakeRange(35, 5))
            .stroke(color: .green, width: 3, range: NSMakeRange(40, 5))
            .textEffect(range: NSMakeRange(50, 5))
            .shadow{
                $0.shadowColor = UIColor.red
                $0.shadowOffset = CGSize(width: 3, height: 3)
                $0.shadowBlurRadius = 2.0
            }.rawValue

// 6. “+”
label7.attributedText = ("昵称: ".toAttributed.font(UIFont.systemFont(ofSize: 18)).foregroundColor(UIColor.red) +
                         "loopeer".toAttributed.font(UIFont.systemFont(ofSize: 13)).underLine(style: [.styleSingle])).rawValue

demo

Installation

1. CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

Specify AttributedStringWrapper into your project's Podfile:

# source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
use_frameworks!

target '<Your App Target>' do
  #swift 3.x
  pod 'AttributedStringWrapper', '~> 1.0.2'  
  
  #swift 4.0
  pod 'AttributedStringWrapper', '~> 1.0.3'
 
end

Then run the following command:

$ pod install

2. Carthage

Carthage is a simple, decentralized dependency manager for Cocoa.

Specify AttributedStringWrapper into your project's Carthage:

github "loopeer/AttributedStringWrapper" ~> 1.0.2

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].