nsrange

How to capture last 4 characters from NSString

别等时光非礼了梦想. 提交于 2019-11-27 11:19:56
问题 I am accepting an NSString of random size from a UITextField and passing it over to a method that I am creating that will capture only the last 4 characters entered in the string . I have looked through NSString Class Reference library and the only real option I have found that looks like it will do what I want it to is - (void)getCharacters:(unichar *)buffer range:(NSRange)aRange I have used this once before but with static parameters 'that do not change', But for this implementation I am

Create UITextRange from NSRange

南楼画角 提交于 2019-11-27 11:12:29
I need to find the pixel-frame for different ranges in a textview. I'm using the - (CGRect)firstRectForRange:(UITextRange *)range; to do it. However I can't find out how to actually create a UITextRange . Basically this is what I'm looking for: - (CGRect)frameOfTextRange:(NSRange)range inTextView:(UITextView *)textView { UITextRange*range2 = [UITextRange rangeWithNSRange:range]; //DOES NOT EXIST CGRect rect = [textView firstRectForRange:range2]; return rect; } Apple says one has to subclass UITextRange and UITextPosition in order to adopt the UITextInput protocol. I don't do that, but I tried

How shouldChangeCharactersInRange works in Swift?

此生再无相见时 提交于 2019-11-27 09:56:29
问题 I'm using shouldChangeCharactersInRange as a way of using on-the-fly type search. However I'm having a problem, shouldChangeCharactersInRange gets called before the text field actually updates: In Objective C, I solved this using using below: -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string]; return YES; } However, I've

How to get all NSRange of a particular character in a NSString?

℡╲_俬逩灬. 提交于 2019-11-27 03:48:42
问题 I have two NSStrings: orgText and searchLetter . I want to highlight every occurrences of the searchLetter in the orgText with a red color. How can I get the NSRange of all occurrences of the searchLetter ? for eg : suppose: orgText = "abcahaiapaoiuiapplma" searchLetter = "a". I want to hightlight all "a" occurrences in "abcahaiapaoiuiapplma" with red color. Thanks. 回答1: I wrote this method for my project - SUITextView with highlight: - (NSMutableAttributedString*) setColor:(UIColor*)color

Make part of a UILabel bold in Swift

二次信任 提交于 2019-11-27 00:42:32
问题 I have a UILabel I've made programmatically as: var label = UILabel() I've then declared some styling for the label, including a font, such as: label.frame = CGRect(x: 20, y: myHeaderView.frame.height / 2, width: 300, height: 30) label.font = UIFont(name: "Typo GeoSlab Regular Demo", size: 15) label.textColor = UIColor(hue: 0/360, saturation: 0/100, brightness: 91/100, alpha: 1) The first part of the label will always read : "Filter:" then followed by another part of the string, for example,

Create UITextRange from NSRange

Deadly 提交于 2019-11-26 15:31:35
问题 I need to find the pixel-frame for different ranges in a textview. I'm using the - (CGRect)firstRectForRange:(UITextRange *)range; to do it. However I can't find out how to actually create a UITextRange . Basically this is what I'm looking for: - (CGRect)frameOfTextRange:(NSRange)range inTextView:(UITextView *)textView { UITextRange*range2 = [UITextRange rangeWithNSRange:range]; //DOES NOT EXIST CGRect rect = [textView firstRectForRange:range2]; return rect; } Apple says one has to subclass

NSRange from Swift Range?

岁酱吖の 提交于 2019-11-26 03:45:55
Problem: NSAttributedString takes an NSRange while I'm using a Swift String that uses Range let text = "Long paragraph saying something goes here!" let textRange = text.startIndex..<text.endIndex let attributedString = NSMutableAttributedString(string: text) text.enumerateSubstringsInRange(textRange, options: NSStringEnumerationOptions.ByWords, { (substring, substringRange, enclosingRange, stop) -> () in if (substring == "saying") { attributedString.addAttribute(NSForegroundColorAttributeName, value: NSColor.redColor(), range: substringRange) } }) Produces the following error: error: 'Range'

NSRange from Swift Range?

南笙酒味 提交于 2019-11-26 01:52:40
问题 Problem: NSAttributedString takes an NSRange while I\'m using a Swift String that uses Range let text = \"Long paragraph saying something goes here!\" let textRange = text.startIndex..<text.endIndex let attributedString = NSMutableAttributedString(string: text) text.enumerateSubstringsInRange(textRange, options: NSStringEnumerationOptions.ByWords, { (substring, substringRange, enclosingRange, stop) -> () in if (substring == \"saying\") { attributedString.addAttribute