nsattributedstring

How can I set the color and alignment of attributed text in a UITextView in iOS 7?

試著忘記壹切 提交于 2019-12-18 11:41:43
问题 The formatting of my textViews worked fine in iOS 6, but no longer in iOS 7. I understand with Text Kit much of the under the hood stuff has changed. It's become really quite confusing, and I'm hoping someone can help straighten it out a bit by helping me with something as simple as this. My static UITextView originally was assigned a value for it's textColor and textAlignment properties. Then I made a NSMutableAttributedString , assigned it an attributes, then assigned it to the textView's

How to set label height for auto adjust in Read More/Less with Swift 3?

99封情书 提交于 2019-12-18 09:44:11
问题 I would like to create the paragraph with Read More/Read Less at the end. Here are my codes; func getLabelHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat { let lbl = UILabel(frame: .zero) lbl.frame.size.width = width lbl.font = font lbl.numberOfLines = 0 lbl.text = text lbl.sizeToFit() lbl.adjustsFontSizeToFitWidth = true return lbl.frame.size.height } @IBAction func btnReadMore(_ sender: Any) { if isLabelAtMaxHeight { btnReadmore.setTitle(NSLocalizedString("Read more", comment:

Find multiple quoted words in a string with regex

拟墨画扇 提交于 2019-12-18 09:24:19
问题 My app supports 5 languages. I have a string which has some double quotes in it. This string is translated into 5 languages in the localizable.strings files. Example: title_identifier = "Hi \"how\", are \"you\""; I would like to bold out "how" and "you" in this string by finding the range of these words. So I am trying to fetch these quoted words out of the string and the result would be an array containing "how" and "you" or their range. func matches(for regex: String, in text: String) ->

Advance search implementation in iphone?

拥有回忆 提交于 2019-12-18 03:35:22
问题 I want to implement advance search functionality so that if a particular text is typed in search bar, the list of contents in UITableview should be filtered based on the search and then the search text occurances should be highlighted? Please give me some ideas? 回答1: Use NSAttributedString... Find UIControllers that draw NSAttribute String because UILabel,UITextView doesnot support NSAttributedString... Get the controller here: https://github.com/AliSoftware/Ali-Cocoa-Classes/tree/master

NSBackgroundColorAttributeName-like attribute in NSAttributedString on iOS?

不问归期 提交于 2019-12-18 02:42:18
问题 I was planning on using NSAttributedString to highlight portions of strings with the matching query of a user's search. However, I can't find an iOS equivalent of NSBackgroundColorAttributeName —there's no kCTBackgroundColorAttributeName . Does such a thing exist, similar to the way NSForegroundColorAttributeName becomes kCTForegroundColorAttributeName ? 回答1: No, such an attribute doesn't exist in Core Text, you'll have to draw your own rectangles underneath the text to simulate it. Basically

How do you stroke the _outside_ of an NSAttributedString?

[亡魂溺海] 提交于 2019-12-17 22:19:35
问题 I've been using NSStrokeWidthAttributeName on NSAttributedString objects to put an outline around text as it's drawn. The problem is that the stroke is inside the fill area of the text. When the text is small (e.g. 1 pixel thick), the stroking makes the text hard to read. What I really want is a stroke on the outside. Is there any way to do that? I've tried an NSShadow with no offset and a blur, but it's too blurry and hard to see. If there was a way to increase the size of the shadow without

Copy NSAttributedString to pasteboard

冷暖自知 提交于 2019-12-17 19:42:57
问题 Brand new to Cocoa and I'm trying to figure out how to copy an NSAttributedString to the pasteboard. I've looked in the docs and not sure if I'm supposed to use a NSPasteboardItem or not. Here's what I have to copy a regular NSString: NSPasteboard *pb = [NSPasteboard generalPasteboard]; NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil]; [pb declareTypes:types owner:self]; [pb setString:@"asdfasdf" forType:NSStringPboardType]; How do I set a NSAttributedString? Thanks 回答1:

UITextField attributedPlaceholder has no effect

柔情痞子 提交于 2019-12-17 19:38:09
问题 I'm trying to make the placeholders in my textfields italic, and since my app is targeting iOS 6.0 or newer, decided to use attributedPlaceholder property instead of rolling something more custom. The code goes as follows: NSString *plString = @"optional"; NSAttributedString *placeholder = [[NSAttributedString alloc] initWithString:plString attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-LightItalic" size:15]}]; for (UITextField *t in myTextfields){ t.placeholder =

NSAttributedString inserting a bullet point?

与世无争的帅哥 提交于 2019-12-17 17:33:37
问题 So I have an NSAttributedString I want to insert a bullet point at the beginning of a portion of text. How can I do this? How do I create a CTPAragraphStyle that creates this bullet point when I display the text? Edit: Should be available on iOS 回答1: The easy bit: [mutableAttributedString insertAttributedString: @"•\t" atIndex:0]; The hard bit. Something along the following lines. (This is extracted from a bigger project, but it may give you a decent start.) NSMutableAttributedString * string

How to calculate the height of an NSAttributedString with given width in iOS 6 [duplicate]

浪子不回头ぞ 提交于 2019-12-17 15:25:51
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to get height for NSAttributedString at a fixed width Now NSAttributedString is available in iOS 6. For layout purposes, I want to know how to calculate the required height of an NSAttributedString under fixed width. I'm looking for something that's equivalent to NSString's - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size but for NSAttributedString. To calculate the drawing size of