目的:修改系统拍摄完成后出现的 重拍 和 使用照片 文字
在调试时我们可以看到如下图的层级结构.只要拿到它并修改文字就可以了.
reusePhoto.png
假如我们想要把使用照片那几个字变更为搜索照片可以按如下方法实现
1.在这个界面将要出现或者已经出现的代理方法中(图片选择控制的代理)找到这个View
-(void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated
我们可以遍历view的找到想要的view
-(UIView *)findView:(UIView *)aView withName:(NSString *)name {
if ([name isEqualToString:NSStringFromClass(aView.class)]){
return aView;
}
for (UIView *view in aView.subviews) {
'if ([name isEqualToString:NSStringFromClass(view.class)]) {
return view;
}
}
return nil;}
然后通过下面方法找到:PLCropOverlayPreviewBottomBar
UIView *PLCropOverlay = [self findView:viewController.view withName:@"PLCropOverlay"];
[PLCropOverlay setValue:@"搜索照片" forKey:@"_defaultOKButtonTitle"];
UIView *PLCropOverlayBottomBar = [self findView:PLCropOverlay withName:@"PLCropOverlayBottomBar"];
UIView *PLCropOverlayPreviewBottomBar = [self findView:PLCropOverlayBottomBar withName:@"PLCropOverlayPreviewBottomBar"];
UIButton *userButton = PLCropOverlayPreviewBottomBar.subviews.lastObject;
[userButton setTitle:@"搜索照片" forState:UIControlStateNormal];
然而实践证明这个方法在选择相机拍照时无效的.但是在选择 图库 时有效的.其中的 选取 会变成 搜索照片.
2.如果解决使用相机时的问题呢
在显示PLCropOverlay相关属性的时候,发现其有个属性是_defaultOKButtonTitle
PLCropOverlay->_defaultOKButtonTitle 我们可以通过KVC进行赋值
在上一步获取PLCropOverlay的时候 通过KVC进行赋值就可以了如下:
[PLCropOverlaysetValue:@"搜索照片"forKey:@"_defaultOKButtonTitle"];
到这一步就搞定了.
备注:
其他在使用图库时也有_defaultOKButtonTitle
属性,但是实践表明,是无效果的,因此上文的最终结果是通过KVC赋值之后,仍然进行了查找子视图的操作.当然你也可以进一步优化.