nsattributedstring

Do I use NSAttributedString or UIWebView Swift

怎甘沉沦 提交于 2019-12-25 02:56:02
问题 I'm getting different strings that occupy "busDescriptio" depending on what business you choose from a website database. This string contains html tags, images, and links. I was told to use NSAttributedString instead of UIWebView because UIWebView was giving me all sorts of problems such as images in wrong place, text font, and text color wouldn't fully work. I'm new to Swift so I cant really wrap my head around how NSAttributedString works. I was able to strip out the html tags and keep the

Type of expression is ambiguous without more context attributed text in Swift 4

别等时光非礼了梦想. 提交于 2019-12-25 01:27:01
问题 I am using a font in the same in attribute: , it is giving above error do { let myAttribute = [ NSAttributedStringKey.font: UIFont(name: "Chalkduster", size: 18.0)! ] let attrStr = try NSAttributedString(data: ("Some String HTML".data(using: String.Encoding.unicode, allowLossyConversion: false)!)!,options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil,attributes: myAttribute) self.NoAccessMessage.font = UIFont

iOS: Adding underlineStyle attribute to NSAttributedString, makes the text view disappear

独自空忆成欢 提交于 2019-12-25 00:53:04
问题 I've create a UITextView in storyboard. Added attributes to the string. All goes well, until I add underlineStyle attribute. Then the text view disappears. class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! override func viewDidLoad() { super.viewDidLoad() let text = "random text <a href='http://www.google.com'>http://www.google.com </a> more random text" let attributedText = htmlStyleAttributeText(text: text)! let underLineColor: UIColor = UIColor(red: 245/255,

NSAttributedString not working as expected in iOS 13

核能气质少年 提交于 2019-12-24 20:09:16
问题 I am using NSMutableAttributedString to show multi font and colour text in a label. NSMutableAttributedString is not working as expected in iOS 13, but same code works fine in iOS 11 and 12 versions. let hdAttributedText = NSMutableAttributedString(string: "Sample", attributes: [NSAttributedString.Key.font: UIFont(name: "HelveticaNeue", size: 14.0)!, NSAttributedString.Key.foregroundColor: UIColor.black]) hdAttributedText.append(NSAttributedString(string: " ")) hdAttributedText.append

Setting foreground color works only once for NSAttributedString

落爺英雄遲暮 提交于 2019-12-24 18:56:44
问题 The phone part of the string gets the underline attribute, but the color remains red. I've separated the color and underline setAttributes() calls, to make things clear, the same happens when it's one call. let text = "call " let phone = "1800-800-900" let attrString = NSMutableAttributedString(string: text + phone, attributes: nil) let rangeText = (attrString.string as NSString).range(of: text) let rangePhone = (attrString.string as NSString).range(of: phone) attrString.setAttributes(

Cocoa NSAttributedString Pasting Changes Font

谁说我不能喝 提交于 2019-12-24 15:42:22
问题 I have an NSAttributedString which has an NSAttachment and some text. I have copied it to the pasteboard. I have also made sure that the string has no font attributes. When I paste it, it always changes the font to Helvetica. Is there any way to prevent this behavior? let wrapper = NSFileWrapper() wrapper.preferredFilename = "image" let attachment = NSTextAttachment(fileWrapper: wrapper) if let im = NSImage(data: data) { attachment.image = im } let image = NSAttributedString(attachment:

UITextView where should I set color and font for for attributed string

你离开我真会死。 提交于 2019-12-24 03:27:25
问题 When I use UITextView in storyboard, I can select text as attributed string and set its attributes like color, font and other attributes. And when I set textView.text = @"my string" in code it show up as I set. My question is if I want to do this in code, what would be equivalent to this storyboard attributes setting? From document https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextView_Class/index.html#//apple_ref/occ/instp/UITextView/text I see some property i.e.

Can't get attributed string to work in Swift

强颜欢笑 提交于 2019-12-24 03:16:57
问题 I'm trying to set some attributes of a string in code, but can't get NSAttributedString to work. This is the function, that's supposed to change the string: func getAttributedString(string: String) -> NSAttributedString { var attrString = NSMutableAttributedString(string: string) var attrs = [NSFontAttributeName : UIFont.boldSystemFontOfSize(18.0)] attrString.setAttributes(attrs, range: NSMakeRange(0, attrString.length)) return attrString } And this is how I use it: if (self.product

Can't seem to calculate correct line-height of NSAttributedString for a UILabel

不打扰是莪最后的温柔 提交于 2019-12-24 01:39:20
问题 I'm using NSAttributedString's boundingRectWithSize:options:context: method to calculate the expected height for some text, after reading this article from objc.io +(CGSize)postLabelSizeForPost:(ANKPost *)post { CGFloat labelWidth = 220.0f; NSAttributedString *text = [BXTPostCell mutableAttributedStringForPost:post]; NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading; CGRect boundingRect = [text boundingRectWithSize:CGSizeMake(labelWidth,

Objective C - NSAttributedString extend Attributes?

房东的猫 提交于 2019-12-24 01:01:25
问题 As the user types into my textfiled I want the new characters to inherit the previous attributes. I currently get the attributes from the previous character and add it as new attribute for the new range? How can I make it so that it extends the previous attributedString instead? // What I have "a"{attribute1 (0,1)} "b"{attribute2 (1,1)} "c"{attribute3(2,1)} // What I'm trying to do "abc" {attribute1 (0,3)} Note: This has to happen for every character that the user types, so as the user type