1. TableView不顯示沒內(nèi)容的Cell怎么辦?
類似于圖1泌枪,我不想讓下面的那些空顯示桦山。很簡單,添加“self.tableView.tableFooterView = [[UIView alloc] init];”試過都說好踏堡,加完這句之后就變成了圖2的樣子猎唁。
2. 自定義了leftBarbuttonItem左滑返回手勢失效了怎么辦?
?self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
? ? ? ? ? ? ? ?initWithImage:img
? ? ? ? ? ? ? style:UIBarButtonItemStylePlain
? ? ? ? ? ? ? target:self
? ? ? ? ? ? ? ?action:@selector(onBack:)];
?self.navigationController.interactivePopGestureRecognizer.delegate = id
3. ScrollView莫名其妙不能在viewController劃到頂怎么辦顷蟆?
?self.automaticallyAdjustsScrollViewInsets = NO;
4. 鍵盤事件寫得好煩躁诫隅,都想摔鍵盤了怎么辦?
? 買個(gè)結(jié)實(shí)的鍵盤帐偎;
? 使用IQKeyboardManager(GitHub上可搜索)逐纬,用完之后腰也不疼了,腿也不酸了削樊。
5. 為什么我的App老是不流暢豁生,到底哪里出了問題兔毒?
如圖:
這個(gè)神器叫做:KMCGeigerCounter ,快去GitHub上搬運(yùn)吧甸箱。
6. 怎么在不新建一個(gè)Cell的情況下調(diào)整separaLine的位置育叁?
?_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);
7. 怎么點(diǎn)擊self.view就讓鍵盤收起,需要添加一個(gè)tapGestures么芍殖?
?- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
3{
? ? [self.view endEditing:YES];
?}
8. 怎么給每個(gè)ViewController設(shè)定默認(rèn)的背景圖片豪嗽?
使用基類啊,少年围小。
9. 想在代碼里改在xib里添加的layoutAttributes昵骤,但該怎么用代碼找?
像拉Button一樣地拉你的約束肯适,nslayoutattribute也是可以拉線的变秦。
10. 怎么像Safari一樣滑動(dòng)的時(shí)候隱藏navigationbar?
1 navigationController.hidesBarsOnSwipe = Yes
復(fù)制代碼
11. 導(dǎo)航條返回鍵帶的title太討厭了框舔,怎么讓它消失蹦玫?
1
2 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
3 ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???forBarMetrics:UIBarMetricsDefault];
復(fù)制代碼
12. CoreData用起來好煩,語法又臭又長怎么辦刘绣?
MagicRecord
13. CollectionView怎么實(shí)現(xiàn)tableview那種懸停的header樱溉?
CSStickyHeaderFlowLayout
14. 能不能只用一個(gè)pan手勢來代替UISwipegesture的各個(gè)方向?
1
2 - (void)pan:(UIPanGestureRecognizer *)sender
3 {
4 typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) {
5 ? ? UIPanGestureRecognizerDirectionUndefined,
6 ? ? UIPanGestureRecognizerDirectionUp,
7 ? ? UIPanGestureRecognizerDirectionDown,
8 ? ? UIPanGestureRecognizerDirectionLeft,
9 ? ? UIPanGestureRecognizerDirectionRight
10 };
11 static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined;
12 switch (sender.state) {
13 ? ? case UIGestureRecognizerStateBegan: {
14 ? ?? ???if (direction == UIPanGestureRecognizerDirectionUndefined) {
15 ? ?? ?? ?? ?CGPoint velocity = [sender velocityInView:recognizer.view];
16 ? ?? ?? ?? ?BOOL isVerticalGesture = fabs(velocity.y) > fabs(velocity.x);
17 ? ?? ?? ?? ?if (isVerticalGesture) {
18 ? ?? ?? ?? ?? ? if (velocity.y > 0) {
19 ? ?? ?? ?? ?? ?? ???direction = UIPanGestureRecognizerDirectionDown;
20 ? ?? ?? ?? ?? ? } else {
21 ? ?? ?? ?? ?? ?? ???direction = UIPanGestureRecognizerDirectionUp;
22 ? ?? ?? ?? ?? ? }
23 ? ?? ?? ?? ?}
24 ? ?? ?? ?? ?else {
25 ? ?? ?? ?? ?? ? if (velocity.x > 0) {
26 ? ?? ?? ?? ?? ?? ???direction = UIPanGestureRecognizerDirectionRight;
27 ? ?? ?? ?? ?? ? } else {
28 ? ?? ?? ?? ?? ?? ???direction = UIPanGestureRecognizerDirectionLeft;
29 ? ?? ?? ?? ?? ? }
30 ? ?? ?? ?? ?}
31 ? ?? ???}
32 ? ?? ???break;
33 ? ? }
34 ? ? case UIGestureRecognizerStateChanged: {
35 ? ?? ???switch (direction) {
36 ? ?? ?? ?? ?case UIPanGestureRecognizerDirectionUp: {
37 ? ?? ?? ?? ?? ? [self handleUpwardsGesture:sender];
38 ? ?? ?? ?? ?? ? break;
39 ? ?? ?? ?? ?}
40 ? ?? ?? ?? ?case UIPanGestureRecognizerDirectionDown: {
41 ? ?? ?? ?? ?? ? [self handleDownwardsGesture:sender];
42 ? ?? ?? ?? ?? ? break;
43 ? ?? ?? ?? ?}
44 ? ?? ?? ?? ?case UIPanGestureRecognizerDirectionLeft: {
45 ? ?? ?? ?? ?? ? [self handleLeftGesture:sender];
46 ? ?? ?? ?? ?? ? break;
47 ? ?? ?? ?? ?}
48 ? ?? ?? ?? ?case UIPanGestureRecognizerDirectionRight: {
49 ? ?? ?? ?? ?? ? [self handleRightGesture:sender];
50 ? ?? ?? ?? ?? ? break;
51 ? ?? ?? ?? ?}
52 ? ?? ?? ?? ?default: {
53 ? ?? ?? ?? ?? ? break;
54 ? ?? ?? ?? ?}
55 ? ?? ???}
56 ? ?? ???break;
57 ? ? }
58 ? ? case UIGestureRecognizerStateEnded: {
59 ? ?? ???direction = UIPanGestureRecognizerDirectionUndefined;
60 ? ?? ???break;
61 ? ? }
62 ? ? default:
63 ? ?? ???break;
64 }
65 }
15. 拉伸圖片的時(shí)候怎么才能讓圖片不變形纬凤?
方法一:
1
2 UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
注:有開發(fā)者提醒這個(gè)已經(jīng)棄用福贞,現(xiàn)在的方法叫resizableImageWithCapInsets。
16. 怎么播放GIF的時(shí)候這么卡停士,有沒有好點(diǎn)的庫挖帘?
FlipBoard出品的FLAnimatedImage太適合你了。
17. 怎么一句話添加上拉刷新恋技?
使用SVPullToRefresh庫:
1 [tableView addPullToRefreshWithActionHandler:^{
2 // prepend data to dataSource, insert cells at top of table view
3 // call [tableView.pullToRefreshView stopAnimating] when done
4 } position:SVPullToRefreshPositionBottom];
18. 怎么把tableview里Cell的小對(duì)勾顏色改成別的顏色拇舀?
?_mTableView.tintColor = [UIColor redColor];
21. 怎么改變uitextfield placeholder的顏色和位置?
繼承uitextfield蜻底,重寫這個(gè)方法:
1 - (void) drawPlaceholderInRect:(CGRect)rect {
2 ? ? [[UIColor blueColor] setFill];
3 ? ? [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
4 }
5
22. 你為什么知道這么多奇怪的花招骄崩?
去Stack Overflow刷問題啊,少年