yaoqiyaoqi
本篇文章记录了iOS开发零碎知识点,简单又实用!
代码写了这么多,但是总是有些知识点在真正需要用到的时候却遗忘了,一直想整理这块知识,最近又总是在赶项目,不管再忙,这块总是要整理起来。
修改UITableviewCell的分割线距离通常需要修改separatorInset属性的top, left, bottom, right:
- (void)tableView:(UITableView *)tableViewwillDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath { if ([cellrespondsToSelector:@selector(setSeparatorInset:)]) { [cellsetSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } if ([cellrespondsToSelector:@selector(setLayoutMargins:)]) { [cellsetSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } if ([cellrespondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) { [cellsetPreservesSuperviewLayoutMargins:NO]; } }
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
myTableView.selectionStyle = UITableViewCellSelectionStyleNone;
子视图超出父视图,子视图点击事件不响应。一般子视图超出父视图,子视图点击等事件是不响应的,因为事件的传递链不会传到超出父视图的视图上面,需要我们用 hitTest:withEvent:
处理下。
- (UIView *)hitTest:(CGPoint)pointwithEvent:(UIEvent *)event { CGPoint hitPoint = [self.cardView.dayRateHelpconvertPoint:pointfromView:self]; if ([self.cardView.dayRateHelppointInside:hitPointwithEvent:event]) return self.cardView.dayRateHelp; return [superhitTest:pointwithEvent:event]; }
注意:如果父视图是UIScrollView,需要设置 self.bgScrollView.clipsToBounds = NO;
,因为 UIScrollView
默认会进行裁剪,会导致超出的部分没有了。
修改UITextField的Placeholder的文字颜色和大小。这里我们使用kvc设置UITextField的私有属性。
[textFieldsetValue:placeholderLabelTextColorforKeyPath:@"_placeholderLabel.textColor"]; [textFieldsetValue:[UIFontsystemFontOfSize:placeholderLabelFont]forKeyPath:@"_placeholderLabel.font"];
修改UIPageControl的选中图片和默认图片。默认也是不允许修改的,需要用到kvc设置。
[self.pageControlsetValue:currentImageforKey:@"_currentPageImage"]; [self.pageControlsetValue:pageImageforKey:@"_pageImage"];
1、将使用照片改成保存至相册;
2、监听拍照按钮点击事件;
3、监听重拍按钮点击事件;
4、在拍照里面添加自定义view放到cameraOverlayView上。
- (void)navigationController:(UINavigationController *)navigationControllerdidShowViewController:(UIViewController *)viewControlleranimated:(BOOL)animated { [selfaddSomeElements:viewController]; } - (UIView *)findView:(UIView *)aViewwithName:(NSString *)name { Class cl = [aViewclass]; NSString *desc = [cldescription]; if ([nameisEqualToString:desc]) return aView; for (UIView *view in aView.subviews) { Class cll = [viewclass]; NSString *stringl = [clldescription]; if ([stringlisEqualToString:name]) { return view; } } return nil; } - (void)addSomeElements:(UIViewController *)viewController { UIView *PLCropOverlay = [selffindView:viewController.viewwithName:@"PLCropOverlay"]; UIView *PLCropOverlayBottomBar = [selffindView:PLCropOverlaywithName:@"PLCropOverlayBottomBar"]; UIView *PLCropOverlayPreviewBottomBar = [selffindView:PLCropOverlayBottomBarwithName:@"PLCropOverlayPreviewBottomBar"]; UIButton *userButton = [PLCropOverlayPreviewBottomBar.subviewsobjectAtIndex:2]; UIButton *viewbtn = [[UIButton alloc]init]; [viewbtnsetTitle:@"保存至相册"forState:UIControlStateNormal]; [viewbtnsetTitleColor:[UIColor whiteColor]forState:0]; viewbtn.backgroundColor = RGB(19, 20, 21); [userButtonaddSubview:viewbtn]; [viewbtnmas_makeConstraints:^(MASConstraintMaker *make) { make.trailing.equalTo(userButton.mas_trailing); make.centerY.equalTo(userButton); }]; viewbtn.userInteractionEnabled = NO; //给拍照加点击事件 UIView *CMKBottomBar = [selffindView:viewController.viewwithName:@"CMKBottomBar"]; UIButton *CMKShutterButton = (UIButton *) [selffindView:CMKBottomBarwithName:@"CMKShutterButton"]; [CMKShutterButtonaddTarget:selfaction:@selector(shutterButtonClicked)forControlEvents:UIControlEventTouchUpInside]; //监听重拍 UIButton *resetButton = [PLCropOverlayPreviewBottomBar.subviewsobjectAtIndex:0]; [resetButtonaddTarget:selfaction:@selector(resetButtonClicked)forControlEvents:UIControlEventTouchUpInside]; }
注意:viewbtn.userInteractionEnabled = NO;的作用是防止这层视图的点击事件影响系统的使用照片按钮的点击事件;在这里给拍照按钮和重拍按钮添加了点击事件,既满足了自己需要做的事情,又不影响系统对这两个按钮的点击事件。
专注于IT行业技术专题,提供IT专题优质文章,欢迎关注标哥的技术博客!加入技术交流群,点击“最新公告”查看!
站长QQ:632840804,微信号:huangyibiao520
本站接收来自大家的投稿,只需要将`.md`文件及所需要的图片文件,整体放到文件夹并压缩,并注明作者及原文链接,发到邮箱: huangyibiao520@163.com 或者 632840804@qq.com
版本声明:本文由标哥的技术博客的作者yaoqi原创撰写,欢迎分享本文,转载请保留出处和链接!