nsmutableattributedstring

Justified text with UITextView and NSMutableAttributedString

女生的网名这么多〃 提交于 2020-01-24 10:27:13
问题 I'm trying to put a justified text for a UITextView with NSMutableAttributedString , the NSMutableAttributedString is composed of different NSAttributedString because I need bold and regular font, so I append different NSString , this is my NSMutableAttributedString : NSAttributedString *one = [[NSAttributedString alloc] initWithString:@"abc" attributes:boldDict]; NSAttributedString *two = [[NSAttributedString alloc] initWithString:@" def" attributes:regularDict]; NSAttributedString *three =

iOS 13 UIAlertController - Color change in attributedMessage and attributedTitle doesn't work

China☆狼群 提交于 2020-01-05 06:44:28
问题 Color change in attributedMessage and attributedTitle doesn't work. Is there a solution for it? Works well on iOS 12 but no longer works on iOS 13. What can be done or is there a solution or a modification? Here's the full snippet: NSString *title=NSLocalizedString(@"Title",nil); NSString *message=NSLocalizedString(@"Message",nil); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];

iOS 13 UIAlertController - Color change in attributedMessage and attributedTitle doesn't work

时光总嘲笑我的痴心妄想 提交于 2020-01-05 06:44:05
问题 Color change in attributedMessage and attributedTitle doesn't work. Is there a solution for it? Works well on iOS 12 but no longer works on iOS 13. What can be done or is there a solution or a modification? Here's the full snippet: NSString *title=NSLocalizedString(@"Title",nil); NSString *message=NSLocalizedString(@"Message",nil); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];

Change UIAlertController's title fontsize

試著忘記壹切 提交于 2020-01-04 15:14:39
问题 I'm trying to change the title fontSize in an UIAlertController , but I can't manage how to set my NSMutableAttributedString to the title -property. So for I've been creating the NSMutableAttributedString with the following code: let title = NSMutableAttributedString(string: user.fullName) let range = NSRange(location: 0, length: title.length) title.addAttribute(NSAttributedStringKey.font, value: UIFont.TextStyle.largeTitle, range: range) Now the tricky part for me is how to figure out how to

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

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:

Trim first character in NSMutableAttributedString

青春壹個敷衍的年華 提交于 2019-12-24 02:55:15
问题 I am using NSMutableAttributedString to show attributed string in label. Is there way to trim first character of NSMutableAttributedString without change in attributes. 回答1: No because one of the attributes of the attributes is the range of the string they effect, and those will become invalid if the string length changes. The best approach would be to reconstruct the attributed string from scratch, which might be simple or difficult, depending on whether you know the attributes to add. 回答2:

NSTextView with long NSMutableAttributedText low scrolling and loading speed

帅比萌擦擦* 提交于 2019-12-24 00:39:55
问题 I have a uitextview that most of times should show long attributedtexts . I use below code for creating my attributed text: //Add each line of doa to an element of array for future usage NSArray *paragraphs = [self.Text componentsSeparatedByString:@"\r\n"]; MixedContent= [[NSMutableAttributedString alloc]init]; ArabicContent= [[NSMutableAttributedString alloc]init]; TranslatedContent= [[NSMutableAttributedString alloc]init]; NSString * temp=@""; for (int i=0; i< paragraphs.count; i++) { if(

how can I change style of pre-selected words in my textView?

核能气质少年 提交于 2019-12-22 08:35:28
问题 This is a follow up to this question How can I change style of some words in my UITextView one by one in Swift? Thanks to @Josh's help I was able to write a piece of code that highlights each word that begins with # - and do it one by one. My final code for that was: func highlight (to index: Int) { let regex = try? NSRegularExpression(pattern: "#(\\w+)", options: []) let matches = regex!.matches(in: hashtagExplanationTextView.text, options: [], range: NSMakeRange(0,

Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

混江龙づ霸主 提交于 2019-12-21 06:59:03
问题 I'm trying to add an underline to some text in my Swift app. This is the code I have currently: let text = NSMutableAttributedString(string: self.currentHome.name) let attrs = [NSUnderlineStyleAttributeName:NSUnderlineStyle.PatternDash] text.addAttributes(attrs, range: NSMakeRange(0, text.length)) homeLabel.attributedText = text But I get this error on the text.addAttributes line: NSString is not identical to NSObject How can I add an attribute contained in an enum to an