nsrange

ios - Replace/delete characters [• ] in UITextView on Enter

好久不见. 提交于 2021-01-28 05:17:30
问题 I have a UITextView with a custom NSTextStorage, where I add a list bullet, after each Enter, if the prior line starts with a list bullet. When a user Enter and there is only a list bullet in the beginning of the line where the cursor is, I remove the list bullet and stay on that line. The first function works as expected. But I have a hard time figuring out how to remove the list bullet. if prefix.isEmpty { let text = string.split(separator: "\n") let next = NSMakeRange(textView

Swift : How do I find the position(x,y) of a letter in a UILabel?

这一生的挚爱 提交于 2020-01-15 03:46:27
问题 I am trying to find the position of a letter in a labelText . The code in Objective C is NSRange range = [@"Good,Morning" rangeOfString:@","]; NSString *prefix = [@"Good,Morning" substringToIndex:range.location]; CGSize size = [prefix sizeWithFont:[UIFont systemFontOfSize:18]]; CGPoint p = CGPointMake(size.width, 0); NSLog(@"p.x: %f",p.x); NSLog(@"p.y: %f",p.y); Please someone tell me how we write the above code in swift ? I am finding it bit difficult to calculate range of a string . 回答1: I

Objective-C: Substring and replace

二次信任 提交于 2020-01-05 08:04:39
问题 I have a NSString which is a URL. This URL need to be cut: NSString *myURL = @"http://www.test.com/folder/testfolder"; NSString *test = [myURL stringByReplacingCharactersInRange:[myURL rangeOfString:@"/" options:NSBackwardsSearch] withString:@""]; I have this URL http://www.test.com/folder/testfolder and I want that the test variable should have the value http://www.test.com/folder/ , so the testfolder should be cut. So I tried to find the NSRange testfolder to replace it with an empty string

Problem using NSRange: Index out of bounds

爷,独闯天下 提交于 2020-01-03 19:33:22
问题 I am trying to detect website URL's in my string and then doing some attribution string stuff like bolding it etc. My regex is defined as: static NSRegularExpression *websiteRegularExpression; static inline NSRegularExpression * WebsiteRegularExpression() { if (!websiteRegularExpression) { websiteRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]" options:NSRegularExpressionCaseInsensitive error:nil]; } return

Problem using NSRange: Index out of bounds

你。 提交于 2020-01-03 19:33:21
问题 I am trying to detect website URL's in my string and then doing some attribution string stuff like bolding it etc. My regex is defined as: static NSRegularExpression *websiteRegularExpression; static inline NSRegularExpression * WebsiteRegularExpression() { if (!websiteRegularExpression) { websiteRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]" options:NSRegularExpressionCaseInsensitive error:nil]; } return

Using character delimiters to find and highlight text in Swift

橙三吉。 提交于 2020-01-01 15:32:12
问题 I previously developed an android app that served as a reference guide to users. It used a sqlite database to store the information. The database stores UTF-8 text without formatting (i.e. bold or underlined) To highlight what sections of text required formatting I enclosed them using delimiter tokens specifically $$ as this does not appear in the database as information. Before displaying the text to the user I wrote a method to find these delimiters and add formatting to the text contained

Get currently typed word in a UITextView

偶尔善良 提交于 2019-12-29 08:04:12
问题 I want to get the currently typed word in a UITextView . A way to get a completely typed word can be found here UITEXTVIEW: Get the recent word typed in uitextview, however, I want to get the word while it is being typed (no matter where it is typed, beginning, middle, end of UITextView ). I guess what defines a word being typed is a whitespace character followed by alphanumeric characters, or if the current location (somehow to figure out with range.location ) is the beginning of the

NSMutableAttributedStrings - objectAtIndex:effectiveRange:: Out of bounds

你说的曾经没有我的故事 提交于 2019-12-28 22:02:08
问题 I'm trying to add some fancy text to a label, but I've run into some problems with the NSMutableAttributedString class. I was trying to achieve four this: 1. Change font, 2. Underline range, 3. Change range color, 4. Superscript range. This code: - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { NSMutableAttributedString* display = [[NSMutableAttributedString alloc] initWithString:@"Hello world!"]; NSUInteger length = [[display string]length] - 1; NSRange wholeRange =

Looping using NSRange

∥☆過路亽.° 提交于 2019-12-28 04:20:13
问题 I'm trying to use NSRange to hold a range of years, such as NSRange years = NSMakeRange(2011, 5); I know NSRange is used mostly for filtering, however I want to loop over the elements in the range. Is that possible without converting the NSRange into a NSArray ? 回答1: It kind of sounds like you're expecting NSRange to be like a Python range object. It's not; NSRange is simply a struct typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; not an object. Once you've

iPhone SDK: Grouped UITableView Sections, List Items not showing under correct section [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-25 18:42:09
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I have a grouped uitableview which has several sections. The sections are showing up fine and the number of rows is correct, however there is a problem with the positioning of the list items. I have an