nsstring

iPhone - Strike out an NSString [duplicate]

独自空忆成欢 提交于 2019-12-08 04:02:01
问题 This question already has answers here : Best way to strike out a text (2 answers) Closed 6 years ago . I would like to know if there is an easy way to strike/cross out some text on the iPhone? Thanks 回答1: Yes and No, NSString is a simple class, that only stores unformated text, but you can use an NSAttributedString to store such information, i.e. NSAttributedString* italicText = [[NSAttributedString alloc] initWithString:myNsString attributes:myCrossOutAttributes]; 回答2:

iOS如何适配与屏幕大小相同的图片

自古美人都是妖i 提交于 2019-12-08 03:32:14
随着ios设备的增多,不同尺寸的屏幕给开发者适配打来困扰,特别是一个全屏的图片,如何适配不同的机型呢,这里介绍一个方法,供大家参考: nsdictionary *LaunchImages = @{@"480":@"launchImage-700",@"568":@"launchImage-710",@"667":@"launchImage-720",@"736":@"launchImage-730"}; nsstring *key = [nsstring stringwithFormat:@"ld",[uiscreen mainscreen].bound.size.height]; self.view.layer.contents = (id)[uiimage imagewithname:launchImages[key]].CGImage; 这就是适配不同机型的代码,大家看看把。 来源: CSDN 作者: IOS菜鸟先飞 链接: https://blog.csdn.net/u010711384/article/details/46051989

修改UIImage 宽高并压缩

只谈情不闲聊 提交于 2019-12-08 03:15:20
//原始图 UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; NSData *data; CGFloat fixelW = image.size.width; CGFloat fixelH = image.size.height; CGFloat maxValue = fixelW; if( fixelH > maxValue){ maxValue = fixelH; } if( maxValue > 800){ CGFloat scaleSize = 800/maxValue; UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize)); [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); data =

stringWithContentsOfURL cookie jar in El Capitan

强颜欢笑 提交于 2019-12-08 01:55:19
I have a small open source application. I used [NSString stringWithContentsOfURL] to download website's html and check if user has been logged in in Safari. Before El Capitan everything was working fine: stringWithContentsOfURL used sharedCookiesStorage (Safari ones) and returned the html of the page as logged in user. But in El Capitan this is not working this way: stringWithContentsOfURL returns the html of the page, where the user is not logged in. So it doesn't use Safari's cookies anymore. (I'm logged in on this page in Safari). There were some changes in El Capitan, I had to add all my

Displaying percentage using NSString

折月煮酒 提交于 2019-12-08 01:34:22
问题 How do we display percentage character in objective-c? I am using this: [NSString localizedStringWithFormat:@"%.2f %", percentageQs] But for some reason, it doesn't recognize the %. thought i could escape it using this \ but i was so wrong. 回答1: There was a similar question tagged C asked earlier today: How to escape the sign in C . Answer here is the same... use a double %%. 回答2: % is used as an escape character, e.g. %@, %i, etc. So to use the % sign then you use two, i.e. %% 回答3: The code

Convert NSString to UIColor

核能气质少年 提交于 2019-12-08 01:34:12
问题 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]; 回答1: I wrote a

Dealing with special characters like (ö, Ä, é, ß) in iOS

寵の児 提交于 2019-12-08 00:21:54
问题 I am fetching data from URL, and this data contains special characters, such as in the name Désirée . I want to display this in my TableView cell, but when I display it, it looks like this: Dösiröe . How do I make it display correctly? Fetch data NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:URL] encoding: NSStringEncodingConversionAllowLossy error:nil]; SBJSON *parser = [[SBJSON alloc] init]; dictShow = [parser objectWithString:jsonString error:nil]; arr=

Is there an easy way to make part of an NSString object a superscript or subscript?

只谈情不闲聊 提交于 2019-12-07 23:44:56
问题 For example, suppose I have an NSString @"20O(2H,1H)19O", and I want all the numbers to be superscript. Is there an easy way to do this? 回答1: I think you probably want NSAttributedString with NSSuperScriptAttributeName. If you need to keep it in an NSString , unicode has characters for superscripted digits. 回答2: This function should return a given number in superscript. Very simple -(NSString *)superScriptOf:(NSString *)inputNumber{ NSString *outp=@""; for (int i =0; i<[inputNumber length]; i

SBJSON parsing NSString to NSDictionary

こ雲淡風輕ζ 提交于 2019-12-07 22:17:22
问题 I'm trying to parse an NSString that contains JSON data into an NSDictionary using SBJson 3.0.4, but when I do it, I get this error: "WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: -[__NSCFString JSONValue]: unrecognized selector sent to instance 0x6ab7a40" As far as I know (which isn't very far), the JSON I'm getting is valid, so I don't know why this is happening. My code compiles fine too… Here it is: NSString *tempURL =

Convert array to NSAttributedString

孤者浪人 提交于 2019-12-07 21:38:42
问题 I have a NSMutableArray composed of NSAttributedString 's. I'm trying to convert it to a single NSAttributedString separating all the NSAttributedString 's with a character. This approach is similar to the conversion of an array to a NSString with the componentsJoinedByString:@"," method but unfortunately this method doesn't exist with the NSAttributedString . How can I convert the array? Thanks. 回答1: I'd to the old way: NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]