nsattributedstring

How to use an NSAttributedString with a ScrollView in SwiftUI?

北城余情 提交于 2020-06-27 18:31:34
问题 I've been able to render NSAttributedString s via UIViewRepresentable which works great until I wrap the view in a ScrollView . When placed inside the ScrollView , the NSAttributedString view stops rendering. I've tried some other methods that replace an NSAttributedString with adding multiple Text() views together to get formatting which works inside the ScrollView and supports italics and monospace font . Unfortunately this doesn't work for links inside text blocks, which means I still need

how to append Attributed Text String with Attributed String in Swift

爱⌒轻易说出口 提交于 2020-06-24 02:57:48
问题 I want to append an Attributed Text with another Attributed Text in Swift. Please provide any sample code for appending operation of two attributed String in Swift. 回答1: Use NSMutableAttributedString Small example let yourAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont.systemFontOfSize(15)] let yourOtherAttributes = [NSForegroundColorAttributeName: UIColor.redColor(), NSFontAttributeName: UIFont.systemFontOfSize(25)] let partOne =

how to append Attributed Text String with Attributed String in Swift

坚强是说给别人听的谎言 提交于 2020-06-24 02:56:34
问题 I want to append an Attributed Text with another Attributed Text in Swift. Please provide any sample code for appending operation of two attributed String in Swift. 回答1: Use NSMutableAttributedString Small example let yourAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont.systemFontOfSize(15)] let yourOtherAttributes = [NSForegroundColorAttributeName: UIColor.redColor(), NSFontAttributeName: UIFont.systemFontOfSize(25)] let partOne =

How to remove bottom padding of UILabel with attributedText inside UIStackView

拜拜、爱过 提交于 2020-05-17 06:18:12
问题 I want to remove the bottom padding of a UILabel with attributedText inside a UIStackview. I found this solution How to remove the extra padding below an one line UILabel. This works with normal text but not with attributed text. let textLabel = UILabel() textLabel.translatesAutoresizingMaskIntoConstraints = false textLabel.text = "What is a chemical property and how can you observe it?" textLabel.numberOfLines = 0 textLabel.lineBreakMode = .byWordWrapping textLabel.backgroundColor =

centering text in a UILabel with an NSAttributedString

雨燕双飞 提交于 2020-05-09 19:24:12
问题 Going through some basic improvements to a application I am working on. Still new to the iOS swift development scene. I figured that the lines of text in my code would automatically be centered because I set the label to center. After a little bit of research I discovered this is not the case. How would I align code like this to center: let atrString = try NSAttributedString( data: assetDetails!.cardDescription.dataUsingEncoding(NSUTF8StringEncoding)!, options:

How to check if UILabel has attributedText or normal text programmatically?

只愿长相守 提交于 2020-04-10 08:11:54
问题 Is there any way to tell if UILabel has its text set using label.attributedText or label.text property? The problem is when you set attributedText , text is also updated and vice versa, so it is not possible to check these properties for nil. 回答1: This is what I use. If range length equals the unattributed text length then the text only has a single attribute and is therefore unattributed. NSRange range; [label.attributedText attributesAtIndex:0 effectiveRange:&range]; BOOL isAttributed =

How to check if UILabel has attributedText or normal text programmatically?

时光怂恿深爱的人放手 提交于 2020-04-10 08:11:08
问题 Is there any way to tell if UILabel has its text set using label.attributedText or label.text property? The problem is when you set attributedText , text is also updated and vice versa, so it is not possible to check these properties for nil. 回答1: This is what I use. If range length equals the unattributed text length then the text only has a single attribute and is therefore unattributed. NSRange range; [label.attributedText attributesAtIndex:0 effectiveRange:&range]; BOOL isAttributed =

How to pull NSImage from NSTextAttachment in NSTextView?

和自甴很熟 提交于 2020-03-06 09:12:55
问题 Goal is to allow user to add NSImage (s) to an NSAttributedString in an NSTextView , and then reverse the process and extract the image(s). With code from here, can add image(s) and have them displayed inline. let attributedText = NSMutableAttributedString(string: string, attributes: attributes as? [String : AnyObject]) let attachment = NSTextAttachment() let imageTest = NSImage(named:"sampleImage") as NSImage? let attachmentCell: NSTextAttachmentCell = NSTextAttachmentCell.init(imageCell:

How to pull NSImage from NSTextAttachment in NSTextView?

烈酒焚心 提交于 2020-03-06 09:09:25
问题 Goal is to allow user to add NSImage (s) to an NSAttributedString in an NSTextView , and then reverse the process and extract the image(s). With code from here, can add image(s) and have them displayed inline. let attributedText = NSMutableAttributedString(string: string, attributes: attributes as? [String : AnyObject]) let attachment = NSTextAttachment() let imageTest = NSImage(named:"sampleImage") as NSImage? let attachmentCell: NSTextAttachmentCell = NSTextAttachmentCell.init(imageCell: