Attributed String의 라이브러리를 편안하게 사용하기 위해 [Swifty Attributed String]
                                            
                                                
                                                
                                                
                                                
                                                
                                                 12974 단어  SwiftNSAttributedString프로그램 라이브러리iOS
                    
⚠️대폭 변경된ver1.0.0이(가) 게시되었습니다. 
상세 정보여기.
개시하다 
스위프트에서 애트리버티드스트링을 사용할 때는 직통NSFontAttributeName 등으로 치면서 꾸미고 싶은 범위를 지정하는 게 번거로워 제작SwiftyAttributedString이라는 프로그램 라이브러리를 만들었다.
개선된 점이 있으면 꼭 알려주세요.
특징. 
스위프트에서 애트리버티드스트링을 사용할 때는 직통
NSFontAttributeName 등으로 치면서 꾸미고 싶은 범위를 지정하는 게 번거로워 제작SwiftyAttributedString이라는 프로그램 라이브러리를 만들었다.개선된 점이 있으면 꼭 알려주세요.
특징.
String에서 쉽게 만들 수 있음NSMutableAttributedStringNSFontAttributeName 등 보충 유효 상태에서 쓸 수 있음let attribute = Attribute(value: .font(.systemFont(ofSize: 16)))
textView.attributedText = "SwiftyAttributedString".add(attribute: attribute)
// "Swifty"の部分だけオレンジ
let attribute = Attribute(value: .foregroundColor(.orange),
                          range: .portion(of: .string("Swifty")))
textView.attributedText = "SwiftyAttributedString".add(attribute: attribute)
// 全てに適応させる場合(rangeは省略可能)
let attribute = Attribute(value: .foregroundColor(.orange),
                          range: .all)
textView.attributedText = "SwiftyAttributedString".add(attribute: attribute)
let attribute = Attribute(values: [.font(.systemFont(ofSize: 16)),
                                   .foregroundColor(.red),
                                   .underlineStyle(1.0),])
textView.attributedText = "SwiftyAttributedString".add(attribute: attribute)
textView.attributedText = "SwiftyAttributedString"
            .add(attribute: Attribute(value: .font(.systemFont(ofSize: 16))))
            .add(attribute: Attribute(value: .foregroundColor(.orange),
                                      range: .portion(of: .string("String"))))
            .add(attribute: Attribute(values: [.underlineStyle(1.0),
                                               .foregroundColor(.blue)],
                                      range: .portion(of: .string("Attributed"))))
 
 가져오기 
Carthage
 Cartfile에 다음과 같은 내용을 보충한다.
Cartfilegithub "touyu/SwiftyAttributedString"
Terminal$ carthage update --platform iOS
CocoaPods
 Podfile에 다음과 같은 내용을 보충한다.
Podfilepod 'SwiftyAttributedString'
Terminal$ pod install
예제 textView.attributedText = "SwiftyAttributedString"
            .add(attribute: Attribute(value: .font(.systemFont(ofSize: 16))))
            .add(attribute: Attribute(value: .font(.boldSystemFont(ofSize: 16)),
                                      range: .portion(of: .string("String"))))
            .add(attribute: Attribute(value: .foregroundColor(.blue),
                                      range: .portion(of: .string("Swifty"))))
            .add(attribute: Attribute(value: .foregroundColor(.red),
                                      range: .portion(of: .string("Attributed"))))
            .add(attribute: Attribute(value: .foregroundColor(.orange),
                                      range: .portion(of: .string("String"))))
            .add(attribute: Attribute(value: .underlineStyle(1.0),
                                      range: .portion(of: .string("Attributed"))))
 
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Attributed String의 라이브러리를 편안하게 사용하기 위해 [Swifty Attributed String]), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/touyu/items/2e08bea72cba85107616
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
github "touyu/SwiftyAttributedString"
$ carthage update --platform iOS
pod 'SwiftyAttributedString'
$ pod install
textView.attributedText = "SwiftyAttributedString"
            .add(attribute: Attribute(value: .font(.systemFont(ofSize: 16))))
            .add(attribute: Attribute(value: .font(.boldSystemFont(ofSize: 16)),
                                      range: .portion(of: .string("String"))))
            .add(attribute: Attribute(value: .foregroundColor(.blue),
                                      range: .portion(of: .string("Swifty"))))
            .add(attribute: Attribute(value: .foregroundColor(.red),
                                      range: .portion(of: .string("Attributed"))))
            .add(attribute: Attribute(value: .foregroundColor(.orange),
                                      range: .portion(of: .string("String"))))
            .add(attribute: Attribute(value: .underlineStyle(1.0),
                                      range: .portion(of: .string("Attributed"))))
 
                Reference
이 문제에 관하여(Attributed String의 라이브러리를 편안하게 사용하기 위해 [Swifty Attributed String]), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/touyu/items/2e08bea72cba85107616텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)