nsmutableattributedstring

Is it possible to get a listing of attributes and ranges for an NSMutableAttributedString?

房东的猫 提交于 2019-12-02 21:39:24
I've created a method that takes a NSAttributedString and I'm looking to dynamically create a subview and label to put the string into. Because attributes like font and size need to be determined to correctly determine the size of the label, I need to determine if it is possible to iterate through values and ranges that have been applied to the attributed string? I understand that I could pass the attributes separately, but for sake of reusability, i'd like to be able to pass as few parameters to the method as possible. Apple expects you to use enumerateAttributesInRange:options:usingBlock: .

Attributed string in tableviewcell not showing bold text until the cell is dequeued and reloaded

家住魔仙堡 提交于 2019-12-01 17:24:47
I have a table view, in which the cells have a label with some attributed text. The text is being set correctly from cellForRowAtIndexPath . The color of the text is being correctly set but the bold attribute is not being displayed until the cell is dequeued. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; Model *model = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.tag = indexPath.row; [cell updateContentWithModel:model atIndexPath:indexPath

Animate a change in part of an NSMutableAttributedString

梦想与她 提交于 2019-12-01 12:06:45
I'm making an iOS app that has a UITextView. When closing a parenthesis in that UITextView, I want to highlight to the user which opening parenthesis it pairs to. So far I've done this using an NSMutableAttributedString and changing the font size of the paired parentheses, which works but is kind of ugly. What I really want is to animate this similarly to the way xcode does the same thing when I close a parenthesis in my code. Is there any way of doing this? Any help is greatly appreciated, though I'm fairly new to this, so please don't assume I know too much :) Here's my code: @IBAction func

Animate a change in part of an NSMutableAttributedString

核能气质少年 提交于 2019-12-01 08:10:51
问题 I'm making an iOS app that has a UITextView. When closing a parenthesis in that UITextView, I want to highlight to the user which opening parenthesis it pairs to. So far I've done this using an NSMutableAttributedString and changing the font size of the paired parentheses, which works but is kind of ugly. What I really want is to animate this similarly to the way xcode does the same thing when I close a parenthesis in my code. Is there any way of doing this? Any help is greatly appreciated,

UITextView attributed text not working when using custom font

↘锁芯ラ 提交于 2019-12-01 07:28:07
问题 I'm using UITextView and I'm setting its font and attributed text by code. Case 1: Custom-font - YES , attribtued text - NO The textView text is displayed in custom font. I want the attribtued text with custom font i.e Message : in this case shold be bolded. Case 2: Custom-font - YES , attribtued text - YES Only the attribtued text(Bold text) is displayed in custom font. The code I have is: - (void)loadTextView { _textView.text=NSLocalizedString(@"more_info_text",nil); _textView.font=[UIFont

Make UITextField which has a static and attributed prefix

我是研究僧i 提交于 2019-12-01 00:46:01
I would like to make a UITextField , which has a static prefix and that the user cannot edit or delete, which at the same time is also attributed with a light gray font color. The editable part of the text field should always be shown in black color. An example is given below: It is essentially for typing in a user name, with a constantly prefixed domain. I have already tried using the textFieldShouldClear and textField:shouldChangeCharactersInRange:replacementString: delegate methods together with NSMutableAttributedString , but simply haven't been able to crack it: - (BOOL)textField:

How to bold some words in my UITextView using NSMutableAttributedString?

回眸只為那壹抹淺笑 提交于 2019-11-30 17:59:03
I have a UITextView and there are certain words I'm casting with NSString stringWithFormat that I'd like to be bolded. I have looked around Stack Overflow and tried to follow the the postings but I guess I'm not understanding it. Here's what I've been playing around with: NSRange boldedRange = NSMakeRange(0, 4); NSString *boldFontName = [[UIFont fontWithName:@"Helvetica-Bold" size:100]fontName]; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.name]; [attrString beginEditing]; [attrString addAttribute:NSFontAttributeName value:boldFontName range

Setting NSLinkAttributeName font color

二次信任 提交于 2019-11-30 17:07:46
I feel like I'm missing something easy but I can't seem to find out how to do this: I set the attribute to a link like so: [myAttrString addAttribute:NSLinkAttributeName value:linkURL range:selectedRange]; That works but the link is blue and I can't seem to change the color. This sets everything except the link to white: [myAttrString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:selectedRange]; Is there another color attribute name that I can't seem to find that is specific to links? Use a UITextView Set the UITextView 's linkTextAttributes like so: textView

How to change colour of the certain words in label - Swift 3 [duplicate]

给你一囗甜甜゛ 提交于 2019-11-30 10:38:19
This question already has an answer here: Changing specific text's color using NSMutableAttributedString in Swift 21 answers Created a Label with a simple text. How can I change the color of the certain words in the label? Swift 3 Like below- Use NSMutableAttributedString to apply colors for different words in a string. Try this, there are already lot of similar questions have the answers in SO. let myLabel = UILabel() var stringOne = "Swift 3 has come" let stringTwo = "has" let range = (stringOne as NSString).range(of: stringTwo) let attributedText = NSMutableAttributedString.init(string:

NSMutableAttributedString initWithData: causing EXC_BAD_ACCESS on rotation

我的未来我决定 提交于 2019-11-30 08:40:59
I display different types of contents in a tableview and calculate the height of each cell using different custom methods, in heightForRowAtIndexPath . One of these custom methods implies converting some html in an NSMutableAttributedString , and then calculating the height of this NSMutableAttributedString . For html conversion I use the new initWithData: method. All works perfectly except when I rotate the screen => I've got an exc_bad_access every time. Using Instruments / Zombies, I've been able lo locate the error, and in fact it's this initWithData: . (When I remove this method and