ios 學習筆記(二)

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,點擊

Certificates, Identifiers & Profiles



   點擊certificates,生成證書並安裝(過程中要先生成一個鑰匙具體流程:進入鑰匙串訪問應用-->證書助理-->從證書頒發機構申請證書-->填寫郵件,名稱,選擇存儲到磁盤
    -->生成並安裝。
b:點擊Identifiers,選中Identifiers下的app ids,點擊右上角的+號,輸入name(隨意)和bundle id(對應應用的bundle id).一直下去直到完成
c:點擊Provisioning Profiles下的all,再點擊右上角的+號,選擇ios app development,點下一步,app id選擇剛纔b步驟中新建的,一直下去直到完成
d:下載c中生成的profile,拖到xcode下。
f:進入xcode,product->archive;等完成後點擊右邊的export,彈出框選擇ad hoc.一直下去到完成。現在可以安裝到別人的手機上了。

certificates作用是用來驗證你是哪個開發者的,也稱爲開發者證書。
identifiers作用是用來驗證你是哪個應用的。
profiles作用是用來打包的,生成時會綁定identifiers。
csr證書是指在本機用證書助理生成的證書,用於生成開發者證書和推送證書。
p12證書是用來導出已安裝的開發者證書和推送證書的,在鑰匙串軟件中導出(注意不要在證書展開的狀態下進行導出)。

發佈了58 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章