IOS開發基礎知識--片段9,ios基礎知識--片段

來源:互聯網
上載者:User

IOS開發基礎知識--片段9,ios基礎知識--片段

1:兩種方法刪除NSUserDefaults所有記錄

//方法一NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; //方法二- (void)resetDefaults {    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];    NSDictionary * dict = [defs dictionaryRepresentation];    for (id key in dict) {        [defs removeObjectForKey:key];    }    [defs synchronize];}

2:設定全域navigation barbuttonitem

#pragma mark 設定全域navigation barbuttonitem -(void)setNaviBarButtonItemImage:(NSString *)imageName andX:(NSInteger)x andY:(NSInteger)y andW:(NSInteger)w andH:(NSInteger)h andTitle:(NSString *)title andSel:(SEL)sel andLOrR:(NSString *)lOr andTitleColor:(UIColor *)color{          UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];     btn.frame =CGRectMake(x,y,w,h);          [btn setTitle:title forState:UIControlStateNormal];          if (imageName.length==0 && title.length==0) {              } else if (imageName.length==0 && title.length!=0) {         [btn setBackgroundColor:[UIColor clearColor]];         [btn setTitleColor:color forState:UIControlStateNormal];     }else if(imageName.length!=0 && title.length==0){         UIImage *image = [UIImage imageNamed:imageName];         [btn setImage:image forState:UIControlStateNormal];     }else if(imageName.length!=0 && title.length!=0){         UIImage *image = [UIImage imageNamed:imageName];         [btn setBackgroundImage:image forState:UIControlStateNormal];         [btn setBackgroundColor:[UIColor clearColor]];         [btn setTitleColor:color forState:UIControlStateNormal];     }               [btn addTarget: self action:sel forControlEvents: UIControlEventTouchUpInside];     UIBarButtonItem *bBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];          if ([lOr isEqualToString:@"left"]) {         [self.navigationItem setLeftBarButtonItem:bBtn];     }else{         [self.navigationItem setRightBarButtonItem:bBtn];     } }

3:UITableView設定Section間距

在使用IOS的UITableView時,時常會用到它的UITableViewStyleGrouped分組多section屬性。而預設的情況下使用該屬性後section之間的間距會比較大,看著很不舒服。那麼可以通過以下的代理方法配置UITableView各個section的間距。原理其實很簡單,顯示效果的各個section間距其實是section頭部和底部的組合。配置他們的間距就是配置各個section的頭部和底部//section頭部間距  - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section  {      return 1;//section頭部高度  }  //section頭部視圖  - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  {      UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];      view.backgroundColor = [UIColor clearColor];      return [view autorelease];  }  //section底部間距  - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section  {      return 1;  }  //section底部視圖  - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section  {      UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];      view.backgroundColor = [UIColor clearColor];      return [view autorelease];  } 

4:解決OBJC_CLASS_$_MBProgressHUD無法引用的問題

雖然用POD把相關檔案已經更新下來,但它卻沒有引入到工程中,要手動對它進行引用(或者直接放棄pod管理此外掛程式,直接引入工程項目原始碼中)Undefined symbols for architecture i386:  "_OBJC_CLASS_$_MBProgressHUD", referenced from:      objc-class-ref in ViewController.old: symbol(s) not found for architecture i386clang: error: linker command failed with exit code 1 (use -v to see invocation)這裡的錯誤是因為你的在building phases中沒有引用相關的標頭檔,因此,只需要在building phase中添加對應的.m檔案就可以了。

5:iOS7 下使用SVPullToRefresh 下拉重新整理導覽列位置錯誤

iOS7 下使用SVPullToRefresh 下拉重新整理導覽列位置錯誤;下拉重新整理之後,tableview的第一列會跑到導覽列的下面;修正:添加如下代碼/** *  下拉重新整理 增加一個; */ //修複下拉重新整理位置錯誤 代碼開始if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {    self.automaticallyAdjustsScrollViewInsets = NO;         UIEdgeInsets insets = self.tableView.contentInset;    insets.top = self.navigationController.navigationBar.bounds.size.height +    [UIApplication sharedApplication].statusBarFrame.size.height;    self.tableView.contentInset = insets;    self.tableView.scrollIndicatorInsets = insets;}//修複下拉重新整理位置錯誤  代碼結束__block RootViewController *bSelf = self; [self.tableView addPullToRefreshWithActionHandler:^{         [bSelf addRows];}]; /** *  拉到最後 載入更多,增加一個; */[self.tableView addInfiniteScrollingWithActionHandler:^{    [bSelf addMoreRow];}];

 6:當改動布局要更新效果時

CGRect headFrame=self.headerView.frame;headFrame.size.height=200;self.headerView.frame = headFrame;[self.headerView setNeedsLayout];[self.headerView layoutIfNeeded];

7:給UITextField增加一個右邊內的圖片按鍵(rightView)

UIButton *addCommentBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40,inputTextViewHeight)];[addCommentBtn setImage:[UIImage imageNamed:@"textViewEditNormal"] forState:UIControlStateNormal];[addCommentBtn addTarget:self action:@selector(addCommentAction) forControlEvents:UIControlEventTouchUpInside];_inputTextView.rightView=addCommentBtn;_inputTextView.rightViewMode=UITextFieldViewModeAlways;

8:NSLog 輸出格式集合

• %@     對象• %d, %i    整數• %u      無符整形• %f       浮點/雙字• %x, %X   二進位整數• %o      八進位整數• %zu     size_t• %p      指標• %e      浮點/雙字 (科學計算)• %g      浮點/雙字• %s       C 字串• %.*s      Pascal字串• %c       字元• %C       unichar• %lld      64位長整數(long long)• %llu      無符64位長整數%Lf       64位雙字

9:設定UIImage的渲染模式:UIImage.renderingMode

設定UIImage的渲染模式:UIImage.renderingMode著色(Tint Color)是iOS7介面中的一個.設定UIImage的渲染模式:UIImage.renderingMode重大改變,你可以設定一個UIImage在渲染時是否使用當前視圖的Tint Color。UIImage新增了一個唯讀屬性:renderingMode,對應的還有一個新增方法:imageWithRenderingMode:,它使用UIImageRenderingMode枚舉值來設定圖片的renderingMode屬性。該枚舉中包含下列值:    1    UIImageRenderingModeAutomatic  // 根據圖片的使用環境和所處的繪圖上下文自動調整渲染模式。      2    UIImageRenderingModeAlwaysOriginal   // 始終繪製圖片原始狀態,不使用Tint Color。      3    UIImageRenderingModeAlwaysTemplate   // 始終根據Tint Color繪製圖片,忽略圖片的顏色資訊。  renderingMode屬性的預設值是UIImageRenderingModeAutomatic,即UIImage是否使用Tint Color取決於它顯示的位置。UIImage *img = [UIImage imageNamed:@ "myimage" ];     img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 使用情境(Toolbar中增加item,item使用背景圖,會出現色調為藍色,如果要為圖片原來的色調,則要修改圖片的渲染,因為目前是渲染成文字的色調):@property (weak, nonatomic) IBOutlet UIBarButtonItem *mycollectionItem;UIImage *collectionItemImage=[UIImage imageNamed:@"bottomCollectionNormal"];collectionItemImage=[collectionItemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];self.mycollectionItem.image=collectionItemImage;

10:navigationController當前頁隱藏後跳回去頁同樣被隱藏

當前頁隱藏代碼:[self.navigationController setNavigationBarHidden:YES];跳轉時:[self.navigationController setNavigationBarHidden:NO];[self.navigationController popViewControllerAnimated:YES];

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.