Git Product home page Git Product logo

attributed's Introduction

Mostly Open Source, Mostly Harmless

Trying to make software development less painful and more fun one repository at a time.

If you have any questions or would like to get in contact please feel free to open an issue or find me on twitter.

attributed's People

Contributors

aikrice avatar arcovv avatar basthomas avatar cocoanib avatar hiragram avatar kapoorsahil avatar muizidn avatar natan avatar nhnam avatar nirma avatar quansai avatar rromanchuk avatar sreshetnyak avatar vfn avatar viettrungphan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

attributed's Issues

Add support for applying attributes within ranges.

As the implementation of the library now stands creating an attributed string composed of different attributes can be done with the addition operator like so:

let baseAttributes = Attributes().font(UIFont(name: "Chalkduster", size: 24.0)!)
let accentedAttributes = baseAttribues.foreground(color: .red) 
                                      .underlineStyle(.styleSingle)

let partOne = "Hello, ".attributed(with: baseAttributes) 
let partTwo = "World!".attributed(with: accentedAttributes)
let attributedString = partOne + partTwo

This works, albeit inconvenient.

Adding functionality to the library that supports applying attributes to ranges would make this task much easier.
Perhaps something like the following:

let baseAttributes = Attributes().font(UIFont(name: "Chalkduster", size: 24.0)!)
let accentedAttributes = baseAttribues.foreground(color: .red) 
                                      .underlineStyle(.styleSingle)

"Hello, World!".attributed(with: [(0..5, baseAttributes ), accentedAttributes])

Where the text with different attributes is specified with a range and attributes and then the remainder of the text is attributed with the attributes contained in the tuple with the nil range.

README: consider removing discussion of stale branches

The bottom of the README contains mentions to development, attributed-3.0 branches; but it appears that those are stale and all development is actually happening on master (which is fine). I was confused by this. Please consider removing the stale branches and this information from the README.

change an attribute of attributedString

consider this scenario:
I have set an attributedText for UILabel

then later based on a condition I need only to change the textColor.

what I'm looking for:

textLabel.at.change(.foregroundColor).to(.yellow)

whats your opinion?

what I do right now is:

var attributes = titleNode.attributedText?.attributes(at: 0, longestEffectiveRange: nil, in: NSMakeRange(0, titleNode.attributedText!.length))
            
            if isSelected {
                attributes?[NSAttributedStringKey.foregroundColor] = selectedTitleColor
            } else {
                attributes?[NSAttributedStringKey.foregroundColor] = normalTitleColor
            }
            
            titleNode.attributedText = NSAttributedString(string: title, attributes: attributes)

Scope errors with cocoapod

I'm using Cocoapods 1.2 and Xcode 8.2.1. I get the following error when trying to use the library:
'font' is inaccessible due to 'internal' protection level
I'm getting this error whether I attempt to set the values through in init closure or set them separately on an existing instance.

Based on my own experience creating libraries with Cocoapods, all properties and methods have to be explicitly marked public even if the parent class/struct is public. Although the NSParagraphStyle related methods in the extension seem to all be marked public, only the init methods in the base class are public.

Write support for ranged attributes

Exactly how this would be implemented is still not something that I have worked out.
Still thinking about how the api would work but maybe something like passing an array of (Range, Attribute) tuples to the attributed(with:) function.

Any input or help would be awesome.

NSString+Attributed.swift stack oveflow

The extension for NSString when used, result on an infinite loop.

extension Attributed where Base == NSString {

    public func attributed(with attributes: Attributes) -> NSAttributedString {
        return attributed(with: attributes)
    }

    public func attributed(_ attributeBlock: (Attributes) -> (Attributes)) -> NSAttributedString {
        return attributed(attributeBlock)
    }
}

I believe the intended behaviour here was to call the String extension, and if so, the could should be:

extension Attributed where Base == NSString {

    public func attributed(with attributes: Attributes) -> NSAttributedString {
        return (self as String).at.attributed(with: attributes)
    }

    public func attributed(_ attributeBlock: (Attributes) -> (Attributes)) -> NSAttributedString {
        return (self as String).at.attributed(attributeBlock)
    }
}

Compiling issues

Pods/AttributedLib/Attributed/String+Attributed.swift:33:61: Cannot convert value of type '[NSAttributedStringKey : Any]' (aka 'Dictionary<NSString, Any>') to expected argument type '[String : Any]?'

Pods/AttributedLib/Attributed/Attributes.swift:48:47: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'kern'

Strikethrough attribute is no longer working?

Uses of strikthrough attribute like this is no longer working.

   attributes.append("Siddarth".at.attributed({
                        $0.strikeThroughStyle(.styleSingle)
                            .lineBreakMode(.byWordWrapping)
                    }))

Result builder based API

I think it would be nice to have a simple DSL that would enable users of Attributed to define Attributed strings with even more ease.

I also can not fetch latest release version of this repo.

My pod search AttributedLib result:

-> AttributedLib (2.1.1)
   Modern Swift µframework for attributed strings.
   pod 'AttributedLib', '~> 2.1.1'
   - Homepage: https://github.com/Nirma/Attributed
   - Source:   https://github.com/Nirma/Attributed.git
   - Versions: 2.1.1, 2.1.0, 2.0.2, 2.0.1, 2.0.0, 1.3.0, 1.2.0, 1.1.0, 1.0.0,
   0.2.2, 0.2.1, 0.2.0, 0.1.1, 0.1.0 [master repo]

I think problem is in here:

s.source           = { :git => 'https://github.com/Nirma/Attributed.git', :tag => s.version.to_s }

I also check your tag position:
image

So I consider maybe you should move the tag at the correct place.

Attributed 3.0 (And beyond)

Intent of this issue

Keep track of what should be added and removed from Attributed and which improvements
should be made to the existing API.

TODO

  • Update the attributes of an existing attributed String
  • Improve Support for applying attributes to ranges of a string
  • Improve Documentation in README
  • Increase code coverage past 70%

set internal dictionary property Public

in some scenarios I need to access internal dictionary.
for example:

let attributes = Attributes {
            return $0.foreground(color: .white)
            .alignment(.center)
            .font(UIFont.DinCondensedBold(of: 17))
        }
        
        let icon = String(value)
        // Get the width and height that the text will occupy.
        let iconSize = icon.size(attributes: attributes)
        
        icon.draw(in:
            CGRect(x: (size.width - iconSize.width)/2.0, y: (size.height - iconSize.height)/2.0, width: iconSize.width, height: iconSize.height),
                  withAttributes: attributes.dictionary)

but dictionary property is internal.

Could check out Attributed with Carthage

Attributes.swift:92:47: error: 'NSBaselineOffsetAttributeName' has been renamed to 'NSAttributedStringKey.baselineOffset'
return self + Attributes(dictionary: [NSBaselineOffsetAttributeName: offset])
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NSAttributedStringKey.baselineOffset
UIKit.NSBaselineOffsetAttributeName:3:12: note: 'NSBaselineOffsetAttributeName' was obsoleted in Swift 3
public let NSBaselineOffsetAttributeName: NSAttributedStringKey

issue on multitarget podfile

I encountered this on pod install (pod version 1.9.3)

[!] Unable to determine Swift version for the following pods:

- `AttributedLib-library` does not specify a Swift version and none of the targets (`PhotographApp`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.

my podfile:

source 'https://cdn.cocoapods.org/'

platform :ios, '12.0'
inhibit_all_warnings!

abstract_target 'PhotographApp' do

  pod 'AttributedLib', '= 3.0.0'
  pod 'Firebase/Messaging', '= 6.30.0'
  pod 'Intercom', '= 7.1.2'
  pod 'IQKeyboardManagerSwift', '= 6.5.5'
  pod 'JWTDecode', '= 2.4.1'
  pod 'lottie-ios', '= 3.1.5'
  pod 'R.swift', '= 5.2.1'
  pod 'RxSwift', '= 5.1.1'
  pod 'Sentry', '= 5.2.1'
  pod "SkeletonView", '= 1.8.1'
  pod 'SwiftLint', '= 0.38.0'
  pod 'Swinject', '= 2.7.1'
  pod 'TTGSnackbar', '= 1.10.3'
  pod 'Moya', '= 14.0.0'

  target 'photograph' do
    use_frameworks!

    target 'photographTests' do
      inherit! :search_paths

      pod 'Alamofire', '= 5.1.0'
      pod 'Cuckoo', '= 1.3.2'
      pod 'RxTest', '= 5.1.1'
    end
  end

  target 'photograph-mock' do
    use_frameworks!
  end

end

I tried the small ruby line script for add swift_version on post_install but its not working. Any hint ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.