1:“#ffffff"轉成ios用的顏色值
- (UIColor *) stringTOColor:(NSString *)str
{
if (!str || [str isEqualToString:@""]) {
return nil;
}
unsigned red,green,blue;
NSRange range;
range.length = 2;
range.location = 1;
[[NSScanner scannerWithString:[str substringWithRange:range]] scanHexInt:&red];
range.location = 3;
[[NSScanner scannerWithString:[str substringWithRange:range]] scanHexInt:&green];
range.location = 5;
[[NSScanner scannerWithString:[str substringWithRange:range]] scanHexInt:&blue];
UIColor *color= [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:1];
return color;
}
2:圖片自適應控件大小縮放
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.autoresizesSubviews = YES;
self.imageView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
3:保存整個對象到Preferences
+ (UserModel *)currentUser{
NSData *encodedUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_key"];
UserModel *user = (UserModel *)[NSKeyedUnarchiver unarchiveObjectWithData:encodedUser];
return user;
}
+ (void)saveCurrentUser:(UserModel *)user{
NSData *encodedUser = [NSKeyedArchiver archivedDataWithRootObject:user];
NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
[settings setObject:encodedUser forKey:@"user_key"];
[settings synchronize];
}
<pre name="code" class="objc">+ (void)logoutUser
{
NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
[settings removeObjectForKey:@"user_key"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
保存單個字符串
+ (void)savePass:(NSString *)pass
{
NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
NSString *str = pass;
[settings removeObjectForKey:@"pass"];
[settings setObject:str forKey:@"pass"];
[settings synchronize];
}
+ (NSString *)getPass
{
NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
return [settings objectForKey:@"pass"];
}
4設置啓動頁用xib
5.在標題欄中添加UISearchBar
//導航條的搜索條
self.searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f,0.0f,200.0f,44.0f)];
self.searchbar.backgroundColor=[UIColor clearColor];
self.searchbar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:self.searchbar.bounds.size];
// [self.searchbar setTintColor:[UIColor redColor]];
[self.searchbar setPlaceholder:@"請輸入交易單後6位數字"];
//將搜索條放在一個UIView上
UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 44)];
searchView.backgroundColor = [UIColor clearColor];
[searchView addSubview:self.searchbar];
self.navigationItem.titleView = searchView;
//取消searchbar背景色
- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
6:打包ipa包
a:進入官網https://developer.apple.com/membercenter/index.action,點擊