Objective-c 的一些学习
Dictionary
NSDictionary * dictionary; dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"good",@"why",@" bye",@"how",nil]; NSMutableDictionary* dic = [NSMutableDictionary dictionary]; if (spuId) { [dic setObject:spuId forKey:@"spuId"]; } if (selectDoctorId) { [dic setObject:selectDoctorId forKey:@"selectDoctorId"]; } if (isFirstTreatment ==0 || isFirstTreatment ==1 ) { [dic setObject:isFirstTreatment? @"true" : @"false" forKey:@"isFirstTreatment"]; } if (isExpert ==0 || isExpert ==1 ) { [dic setObject:isExpert? @"true" : @"false" forKey:@"isExpert"]; } if (gps) { [dic setObject:gps forKey:@"gps"]; NSEnumerator * enumerator = [dictionary keyEnumerator]; id obj; while( obj = [enumerator nextObject]) { NSString* val = [dictionary objectForKey:obj]; NSString* param =(NSString*)obj; if (val) { if(![url hasSuffix:@"?"]){ [url appendFormat:@"&"]; } [url appendFormat:[NSString stringWithFormat:@"%@=%@", param, val]]; } }
NSArray
NSMutableArray *docList = [NSMutableArray array]; [docList removeAllObjects]; [docList addObjectsFromArray:obj];
元编程
@interface NSString (URLFormat) - (NSString *)stringByURLFormat:(NSDictionary *)dictionary; @end #import "NSString+URLFormat.h" @implementation NSString (URLFormat) - (NSString *)stringByURLFormat:(NSMutableDictionary *)dictionary{ if([dictionary count]==0) return self; NSMutableString* url = [[NSMutableString alloc] initWithString:self]; [url appendFormat:@"?"]; NSEnumerator * enumerator = [dictionary keyEnumerator]; id obj; while( obj = [enumerator nextObject]) { NSString* val = [dictionary objectForKey:obj]; NSString* param =(NSString*)obj; if (val) { if(![url hasSuffix:@"?"]){ [url appendFormat:@"&"]; } [url appendFormat:[NSString stringWithFormat:@"%@=%@", param, val]]; } } if([url hasSuffix:@"?"]) [url deleteCharactersInRange:NSMakeRange (url.length-1, 1)]; return url; } @end
1、字符串拼接
NSString*newString=[NSStringstringWithFormat:@"%@%@",tempA,tempB];
2、字符串转int
intintString=[newStringintValue];
3、int转字符串
NSString*stringInt=[NSStringstringWithFormat:@"%d",intString];
4、字符串转float
floatfloatString=[newStringfloatValue];
5、float转字符串
NSString*stringFloat=[NSStringstringWithFormat:@"%f",intString];
设置颜色
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert alpha:(CGFloat)alpha { NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; if ([cString length] < 6) return DEFAULT_VOID_COLOR; if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1]; if ([cString length] != 6) return DEFAULT_VOID_COLOR; NSRange range; range.location = 0; range.length = 2; NSString *rString = [cString substringWithRange:range]; range.location = 2; NSString *gString = [cString substringWithRange:range]; range.location = 4; NSString *bString = [cString substringWithRange:range]; unsigned int r, g, b; [[NSScanner scannerWithString:rString] scanHexInt:&r]; [[NSScanner scannerWithString:gString] scanHexInt:&g]; [[NSScanner scannerWithString:bString] scanHexInt:&b]; return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:alpha]; }
相关推荐
84407518 2012-07-16
87214552 2015-10-27
84407518 2016-01-25
89283517 2012-06-19
ObjectiveC 2012-06-14
zhujiangtaotaise 2020-01-01
AllenG 2013-07-07
Beatopcoder 2013-07-14
afrtooylsw 2014-05-14
让编程改变世界 2015-03-13
shqhope 2015-04-09
zoutian00 2015-05-12
huangshm 2019-01-14
86981633 2019-06-29
我的iOS王者之路 2019-06-28
好好学习天天 2019-06-28