我正在使用UIDocumentInteractionController
類來預覽文檔。是否可以更改完成按鈕以關閉另一個預覽?例如,我想設置一個不同的標題:「關閉」而不是「完成」。編程iOS:文檔預覽,更改完成按鈕
0
A
回答
2
改變完成按鈕以完成按鈕實例:
我讀了你可以從lastObject導航項目並改變向左或向右按鈕。
要更改完成按鈕,您需要等待控制器UIDocumentInteractionController視圖才能完成顯示。可悲的是有沒有知道的方法,但有:
- (無效)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)控制器
這會告訴你,它開始時。
我該怎麼做:添加一個計時器,當控制器準備就緒,然後獲取導航欄項目按鈕並將其替換爲新的。在.H
1)在.M
#import "UIView+BK.h"
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller{
//Start timer
_timer = [NSTimer scheduledTimerWithTimeInterval:.05
target:self
selector:@selector(checkNavigationBar)
userInfo:_timer
repeats:YES]; //YES TO CYCLE
}
- (void) checkNavigationBar
{
//get the last view open (the UIDocumentInteractionController View)
UIView *lastWindow = [[[[UIApplication sharedApplication] keyWindow ] subviews] lastObject];
//Find the controller the view belongs too.
UIViewController *controller = [lastWindow findViewController];
if (controller) {
//find navigation bar using a category
UINavigationBar *bar = [controller.view navigationBarFromView];
//get the navigationItem
UINavigationItem *item = bar.topItem;
//get the done button
UIBarButtonItem *doneButton = item.leftBarButtonItem ;
//Creates the new button
UIBarButtonItem *newDoneButton = [[UIBarButtonItem alloc ]
initWithTitle:@"Finished"
style:UIBarButtonItemStylePlain
target:doneButton.target
action:doneButton.action];
//change done button
item.leftBarButtonItem = newDoneButton;
//Stop timer
[_timer invalidate];
_timer = nil;
}
}
3添加這個代理和定時器
.. UIViewController <UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) NSTimer *timer;
2)),則需要此類別
頭類別:
進口
@interface UIView (BK)
- (UIViewController *)findViewController;
- (UINavigationBar *)navigationBarFromView;
@end
實施類別:
#import "UIView+BK.h"
@implementation UIView (BK)
- (UIViewController *)findViewController {
Class vcc = [UIViewController class]; // Called here to avoid calling it iteratively unnecessarily.
UIResponder *responder = self;
while ((responder = [responder nextResponder])) if ([responder isKindOfClass: vcc]) return (UIViewController *)responder;
return nil;
}
- (UINavigationBar *)navigationBarFromView {
for (UIView *subview in self.subviews) {
if ([subview isKindOfClass:[UINavigationBar class]]) {
return (UINavigationBar *)subview;
}
UIView *result = [subview navigationBarFromView];
if (result) {
return (UINavigationBar *)result;
}
}
return nil;
}
@end
相關問題
- 1. 更改IOS完成按鈕文本
- 2. 編輯/完成按鈕,更改完成按鈕背景顏色
- 3. 生成WagtailCMS文檔預覽
- 4. iOS Swift 2.0完成按鈕
- 5. iOS的「完成」按鈕來解除模態或完成編輯?
- 6. 更改UIWebView完成按鈕顏色
- 7. UITableView編輯/完成按鈕
- 8. UITableview編輯/完成按鈕
- 9. 如何更改「瀏覽」按鈕文本
- 10. 是否可以將完成按鈕文本更改爲在嚮導中完成?
- 11. 在鍵盤上更改完成按鈕的文本
- 12. 在iOS8中更改鍵盤上已完成按鈕的文本
- 13. Android:更改鍵盤上的「完成」按鈕文本
- 14. 預覽PDF文檔
- 15. 更改按鈕樣式編程
- 16. 更改按鈕繪製對象編程
- 17. 編程方式更改按鈕
- 18. 我可以更改vim完成預覽窗口高度嗎?
- 19. iOS Xcode鍵盤完成按鈕功能
- 20. iOS完成按鈕重定向到jsp
- 21. MPMovieController完成按鈕=在iOS 5
- 22. 更改iOS中按鈕和禁用按鈕的文本
- 23. 瀏覽器後退按鈕否定了由javascript完成的CSS更改
- 24. 更改iOS虛擬鍵盤「上一個」,「下一個」,「完成」按鈕的語言
- 25. iOS/Android瀏覽器:顯示touchmove上的縮放按鈕預覽
- 26. 如何更改Netbeans字體和顏色預覽文檔?
- 27. MvvmCross:PictureChooser Plugin - 預覽屏幕按鈕文字
- 28. 檢測瀏覽器DOM更改完成
- 29. Tinymce預覽插件按鈕
- 30. django updateview預覽按鈕
有下一個不同的問題有很大幾個答案,如果有人在這裏結束了:http://stackoverflow.com/questions/6855008/change-color-of-uidocumentinteractioncontroller-nav-酒吧 – TahoeWolverine 2015-03-24 19:24:40