nsstring

Always getting the same height using sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

末鹿安然 提交于 2019-12-06 11:36:26
问题 The CGSize returned by sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: contains always the same height. Why is that, and is there a way around this? I want to align a string vertically and it may not be truncated, unless it can't fit on a single line using the minimum font size. So I try to use this method to get the line height but it always returns 57px no matter what the actualFontSize is. Any ideas? 回答1: I believe you are misunderstanding the actualFontSize parameter. This

Convert NSString to NSArray [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 11:09:32
This question already has answers here : Comma-separated string to NSArray in Objective-C (2 answers) Closed 6 years ago . I have one string as follows: NSString *str = @"abcd,efgh"; Now I want to convert this string into NSMutableArray like NSMutableArray *arr = {abcd,efgh}; then how can I do this? any help would be appreciated. NSArray *arr = [@"abcd,efgh" componentsSeparatedByString:@","]; should do the job. 来源: https://stackoverflow.com/questions/15271450/convert-nsstring-to-nsarray

Convert NSString to UIColor

不打扰是莪最后的温柔 提交于 2019-12-06 10:42:35
I have an array full of NSStrings and I need to use an NSString to change the color on an attributed text. I seperated the original NSString into an array containing the single NSString with the color but I am stuck here. The string from the array is [UIColor orangecolor]. I have tried this but it returns null. SEL blackSel = NSSelectorFromString(@"blackColor"); UIColor* tColor = nil; if ([UIColor respondsToSelector: blackSel]) tColor = [UIColor performSelector:blackSel]; I wrote a custom NSValueTransformer to allow me to translate NSColor to NSString (and back) for storage into NSUserDefaults

Encrypt NSString using AES-128 and a key

匆匆过客 提交于 2019-12-06 10:36:10
I have a basic notes app, and I want to allow the user to have encrypted or secure notes. I have an UI whipped up, but right now, I can't seem to get encryption working. Either it returns me a bunch of garbage or nothing at all. This is what I use to en/decrypt: - (BOOL) encryptWithAES128Key: (NSString *) key { // 'key' should be 16 bytes for AES128, will be null-padded otherwise char * keyPtr[kCCKeySizeAES128+1]; // room for terminator (unused) bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) // fetch key data [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding

Tap gesture to part of a UITextView

混江龙づ霸主 提交于 2019-12-06 09:42:01
问题 I have this code: UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapResponse)]; singleTap.numberOfTapsRequired = 1; [_textView addGestureRecognizer:singleTap]; This will react to the entire UITextView, but is it possible to change it so that it only responds to when a certain part of the string in the UITextView is tapped? Like a URL for example? 回答1: You cannot assign tap gesture to particular string in normal UITextView. You can

Drawing a checkmark NSString with UIKit doesn't respect fill color

左心房为你撑大大i 提交于 2019-12-06 09:40:52
I'm trying to draw a checkmark in green with UIKit, but it is drawn in black instead. Here is the code: [[UIColor greenColor] set]; [@"✔" drawAtPoint:CGPointZero withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; Other strings are properly drawn in green with this method. I suspect that the checkmark glyph contains color information that overrides my choice of fill color, but drawing the same glyph with color in an UIWebView works. Is there a way to get the checkmark drawn in green anyway? I suspect that the checkmark glyph in question might not be available in the system font, and

How to clear cookies for specific domain in iOS?

坚强是说给别人听的谎言 提交于 2019-12-06 09:29:05
问题 I have searched almost all questions on StackOverflow for answer to my question. I haven't found any useful link or tutorial saying which way is best to clear cookies for particular domain. So please if someone could help me. 回答1: I found solution myself. If you wish to delete entire cookies in your UIWebView do this. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSHTTPCookie *cookie; for (cookie in [storage cookies]) { NSLog(@"%@", cookie); // Print the

How to strip special characters out of string?

三世轮回 提交于 2019-12-06 09:13:50
问题 I have a set with the characters I allow in my string: var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ") I want to strip any other characters from a string so two unformatted data can be considered equal, like this: "American Samoa".lowercaseString == "american_samoa1".lowercaseString the lowercase version of these transformed strings would be "americansamoa" 回答1: Let's write a function for that (in swift 1.2). func

Weird behaviour of boundingRectWithSize:options:attributes:context:

人走茶凉 提交于 2019-12-06 07:41:34
I am experiencing a strange issue related to boundingRectWithSize:options:attributes:context: This is the code NSString *text = @"These long strings work"; CGSize maxSize = CGSizeMake(176.0f, MAXFLOAT); CGRect rect = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:16.0]} context:nil]; CGSize size = rect.size; I have an xcode iOS project which uses this code. When I run the project, the size is (width=149.8125, height=18.1796875) I created a new single page application project in xcode and tested the

Does XCode creates one object for all empty strings?

拥有回忆 提交于 2019-12-06 07:18:49
i've noticed that all @"" objects create one reference for all times it is executed. NSString *s1=@""; NSString *s2=@""; In this sample s1 equals s2. @"" will create one pointer in all cases, every time i use it? Can i rely on this feature in comparing strings in objective-c? Or simply, can i use this statement, if i want to assure that my string is empty: if(s == @""){ //do something } Yes Objective C has an optimization in the compiler that simply points all equivalent string literals to the same string in memory to avoid allocating unnecessary resources. This feature is reliable but there