ios 開發常用技巧
阿新 • • 發佈:2019-01-10
1.TableView不顯示沒內容的Cell怎麼辦?
self.tableView.tableFooterView = [[UIView alloc] init];
2.自定義了leftBarbuttonItem左滑返回手勢失效了怎麼辦?
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(onBack:)]; self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
(最好在父控制器裡寫)
3.ScrollView莫名其妙不能在viewController劃到頂怎麼辦?
self.automaticallyAdjustsScrollViewInsets = NO;
4.鍵盤事件寫的好煩躁,都想摔鍵盤了,怎麼辦?
使用IQKeyboardManager(github上可搜尋)
5.1、禁止手機睡眠
[UIApplication sharedApplication].idleTimerDisabled = YES;
6.隱藏某行cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // 如果是你需要隱藏的那一行,返回高度為0 if(indexPath.row == YouWantToHideRow) return 0; return 44; }// 然後再你需要隱藏cell的時候呼叫 [self.tableView beginUpdates]; [self.tableView endUpdates];
7.禁用button高亮
button.adjustsImageWhenHighlighted = NO;
或者在建立的時候
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
8.畫水印
// 畫水印
- (void) setImage:(UIImage *)image withWaterMark:(UIImage *)mark inRect:(CGRect)rect { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) { UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0); } //原圖 [image drawInRect:self.bounds]; //水印圖 [mark drawInRect:rect]; UIImage *newPic = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.image = newPic; }
9.cell去除選中效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
10.cell點按效果
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}