diff --git a/KINWebBrowser/KINWebBrowserViewController.h b/KINWebBrowser/KINWebBrowserViewController.h index 64a5087..e9d6814 100644 --- a/KINWebBrowser/KINWebBrowserViewController.h +++ b/KINWebBrowser/KINWebBrowserViewController.h @@ -112,9 +112,21 @@ @property (nonatomic, assign) BOOL showsURLInNavigationBar; @property (nonatomic, assign) BOOL showsPageTitleInNavigationBar; -//Allow for custom activities in the browser by populating this optional array +/* + Allow for custom activities in the browser by populating this optional array + + Warning: Custom activities is actualy not the right name for this property. + This array will be used as applicationActivities in UIActivityViewController's initWithActivityItems:applicationActivities:, not as activityItems as the name suggests. + It should be renamed to something like customApplicationActivities, but this would be a breaking change. + */ @property (nonatomic, strong) NSArray *customActivityItems; +/* + Allow for custom share items in the browser by populating this optional array + It will be used as activityItems in UIActivityViewController's initWithActivityItems:applicationActivities: + */ +@property (nonatomic, strong) NSArray *customShareItems; + #pragma mark - Public Interface diff --git a/KINWebBrowser/KINWebBrowserViewController.m b/KINWebBrowser/KINWebBrowserViewController.m index 253cd25..928bbef 100644 --- a/KINWebBrowser/KINWebBrowserViewController.m +++ b/KINWebBrowser/KINWebBrowserViewController.m @@ -374,7 +374,21 @@ - (void)updateToolbarState { URLString = [URLString stringByReplacingOccurrencesOfString:@"http://" withString:@""]; URLString = [URLString stringByReplacingOccurrencesOfString:@"https://" withString:@""]; URLString = [URLString substringToIndex:[URLString length]-1]; - self.navigationItem.title = URLString; + + UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.navigationController.navigationBar.bounds.size.width, 29.0f)]; + titleView.backgroundColor = [UIColor colorWithRed:228/255.0f green:228/255.0f blue:230/255.0f alpha:1.0]; + titleView.layer.cornerRadius = 5.0f; + + UILabel *label = [[UILabel alloc] init]; + label.font = [UIFont systemFontOfSize:17.0f]; + label.text = URLString; + label.textColor = [UIColor darkGrayColor]; + label.textAlignment = NSTextAlignmentCenter; + label.frame = CGRectInset(titleView.frame, 10.0f, 0.0f); + label.autoresizingMask = UIViewAutoresizingFlexibleWidth; + [titleView addSubview:label]; + + self.navigationItem.titleView = titleView; } } else { @@ -481,8 +495,13 @@ - (void)actionButtonPressed:(id)sender { URLForActivityItem = self.uiWebView.request.URL; URLTitle = [self.uiWebView stringByEvaluatingJavaScriptFromString:@"document.title"]; } - if (URLForActivityItem) { + if (URLForActivityItem || self.customShareItems) { dispatch_async(dispatch_get_main_queue(), ^{ + NSArray *shareItems = @[URLForActivityItem]; + if (self.customShareItems) { + shareItems = self.customShareItems; + } + TUSafariActivity *safariActivity = [[TUSafariActivity alloc] init]; ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init]; @@ -493,7 +512,7 @@ - (void)actionButtonPressed:(id)sender { [activities addObjectsFromArray:self.customActivityItems]; } - UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[URLForActivityItem] applicationActivities:activities]; + UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:activities]; if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { if(self.actionPopoverController) {