nsmutableattributedstring

Change text color of WKInterfaceLabel using NSMutableAttributedString

谁说胖子不能爱 提交于 2019-12-04 11:49:47
I'm trying to change text color in WKInterfaceLabel using setAttributedText property. Here's the code: MyRowController *row = [self.interfaceTable rowControllerAtIndex:idx]; NSString *str_tmp = @"Test"; NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str_tmp]; [text addAttribute:NSFontAttributeName value:[UIFont fontWithName:FONT_REGULAR size:12.0] range:NSMakeRange(0, str_tmp.length)]; [text addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, str_tmp.length)]; [row.lines setAttributedText:text]; The result: Only the

create an attributed string out of plain (Android formatted) text in swift for iOS

痞子三分冷 提交于 2019-12-04 11:30:02
问题 I am reading strings out of a Localizable.strings which contains something like that which is basically what you have in an strings.xml of an Android app "testShort" = "A <b>short</b>\ntest with another<b>bold text</b>"; The bold and and line feed are the only two formatting attributes I have in my texts. I am trying to develop a method like this for days now without success: func ConvertText(inputText: String) -> NSAttributedString { // here comes the conversion to a representation with

Apply rich text format on selected text of UITextView in iOS

淺唱寂寞╮ 提交于 2019-12-04 09:33:47
问题 I am creating an app in which i have to implement functionality like this: 1) Write into textview 2) Select text from textview 3) Allow user to apply bold,italic and underline functionality on selected text. I have started implementing it using NSMutableAttributedString. It's working for bold and italic but replaces the textview text with only selected text. -(void) textViewDidChangeSelection:(UITextView *)textView { rangeTxt = textView.selectedRange; selectedTxt = [textView textInRange

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

纵饮孤独 提交于 2019-12-04 03:22:41
问题 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

Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

大憨熊 提交于 2019-12-03 22:35:15
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 NSMutableAttributedString in Swift? Here's a full example of creating a UILabel with underlined text: Swift 5: let homeLabel

Make UITextField which has a static and attributed prefix

十年热恋 提交于 2019-12-03 22:08:24
问题 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

Crash in iOS 7.0.3 for NSMutableAttributedString [duplicate]

♀尐吖头ヾ 提交于 2019-12-03 22:01:37
This question already has answers here : Closed 5 years ago . What happened to “HelveticaNeue-Italic” on iOS 7.0.3 (10 answers) Since a few days, I have a crash that only happens in iOS with the following line of code [myAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Italic" size:myLabel.font.pointSize] range:rangeOfSubString]; The reason given by debugger is "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString addAttribute:value:range:: nil value'" Exception Type: SIGABRT I know from

iOS - How to use `NSMutableString` in swift

橙三吉。 提交于 2019-12-03 16:25:45
I have seen this Objective-C code but I'm struggling to do the same in swift: NSMutableAttributedString *res = [self.richTextEditor.attributedText mutableCopy]; [res beginEditing]; __block BOOL found = NO; [res enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, res.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { if (value) { UIFont *oldFont = (UIFont *)value; UIFont *newFont = [oldFont fontWithSize:oldFont.pointSize * 2]; [res removeAttribute:NSFontAttributeName range:range]; [res addAttribute:NSFontAttributeName value:newFont range:range]; found = YES; } }];

create an attributed string out of plain (Android formatted) text in swift for iOS

♀尐吖头ヾ 提交于 2019-12-03 08:15:49
I am reading strings out of a Localizable.strings which contains something like that which is basically what you have in an strings.xml of an Android app "testShort" = "A <b>short</b>\ntest with another<b>bold text</b>"; The bold and and line feed are the only two formatting attributes I have in my texts. I am trying to develop a method like this for days now without success: func ConvertText(inputText: String) -> NSAttributedString { // here comes the conversion to a representation with Helvetica 14pt and Helvetica-Bold 14pt including line feeds. } My final goal is to display the text in an

Apply rich text format on selected text of UITextView in iOS

泄露秘密 提交于 2019-12-03 03:24:53
I am creating an app in which i have to implement functionality like this: 1) Write into textview 2) Select text from textview 3) Allow user to apply bold,italic and underline functionality on selected text. I have started implementing it using NSMutableAttributedString. It's working for bold and italic but replaces the textview text with only selected text. -(void) textViewDidChangeSelection:(UITextView *)textView { rangeTxt = textView.selectedRange; selectedTxt = [textView textInRange:textView.selectedTextRange]; NSLog(@"selectedText: %@", selectedTxt); } -(IBAction)btnBold:(id)sender {