iOS 開發技巧

一.UITabelView

1.去掉多余的cell

_tableView.tableFooterView = [[UIView alloc] init];

2.tableview或者scrollview不能再VC中滑到頂

self.automaticallyAdjustsScrollViewInsets = NO;

3.tableview加個默認隱藏的搜索框

self.tableView.tableHeaderView=self.searchDisplayController.searchBar;

self.tableView.contentOffset=CGPointMake(0,CGRectGetHeight(self.searchDisplayController.searchBar.bounds));

4.全屏顯示tableview的分割線

cell.layoutMargins=UIEdgeInsetsZero;

_mineTableView.separatorInset=UIEdgeInsetsZero;

_mineTableView.layoutMargins=UIEdgeInsetsZero;

5.修改cell被選中的顏色

cell.selectedBackgroundView.backgroundColor= [UIColorredColor];

cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

二.導航欄、VC

1.滑動隱藏導航欄

self.automaticallyAdjustsScrollViewInsets = NO;

2.導航欄返回鍵帶的title不好看,換掉

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

3.把navigationBar變成透明

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

self.navigationController.navigationBar.translucent = YES;

4.去掉navigationBar下面的黑色細線

[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];

self.navigationController.navigationBar.shadowImage = [UIImage new];

5.去掉tabBar下面的黑色細線

[self.tabBarController.tabBar setBackgroundImage:[UIImage new]];

[self.tabBarController.tabBar setShadowImage:[UIImage new]];

6.導航欄遮住了Y為0 的控件

(1)

self.edgesForExtendedLayout = UIRectEdgeNone;

(2)

self.navigationController.navigationBar.translucent = NO;

3.UIbutton

1.文字左側顯示

button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;

button.contentEdgeInsets=UIEdgeInsetsZero;

4.收起鍵盤(最好在基類)

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

[self.view endEditing:YES];

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

}

5.截屏

- (void)screenShot

{

UIViewController *vc = [WPMethodManager getFrontViewController];

CGSize size = vc.view.frame.size;

// 開啟上下文,使用參數之后,截出來的是原圖(YES? 0.0 質量高)

UIGraphicsBeginImageContextWithOptions(size, YES, 0);

// 裁剪的關鍵代碼,要裁剪的矩形范圍

CGRect rect = CGRectMake(0, -20, size.width, size.height + 20);

//注:iOS7以后renderInContext:由drawViewHierarchyInRect:afterScreenUpdates:替代

[vc.view drawViewHierarchyInRect:rect afterScreenUpdates:YES];

// 從上下文中,取出UIImage

UIImage *shotImage = UIGraphicsGetImageFromCurrentImageContext();

//保存

UIImageWriteToSavedPhotosAlbum(shotImage, nil, nil, nil);

//結束上下文(移除棧頂上下文)

UIGraphicsEndImageContext();

}

三.Tabbar

1.pop返回指定的tabbar selectedIndex

AYTabBarController *tabBar = (AYTabBarController *)kkeyWindow.rootViewController;

[self.navigationController popToRootViewControllerAnimated:YES];

tabBar.tabBar.hidden = NO;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

tabBar.selectedIndex = 1;

});

? ?注意:tabbarC如果是自定義的就拿到自定義的tabbarC

四.UITextField、UITextView

1.文字內容偏移

????1.UITextField

_circleNameTextField.leftView = [[UIView alloc] initWithFrame:kCGRect(0, 0, 10, _circleNameTextField.jk_height)];

_circleNameTextField.leftViewMode = UITextFieldViewModeAlways;

? ? 2.UITextView

_detailTextView.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 0);


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容