Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _picker = (GMImagePickerController)NavigationController.ParentViewController;
            View.BackgroundColor = _picker.PickerBackgroundColor;

            // Navigation bar customization
            if (!string.IsNullOrWhiteSpace(_picker.CustomNavigationBarPrompt))
            {
                NavigationItem.Prompt = _picker.CustomNavigationBarPrompt;
            }

            _imageManager = new PHCachingImageManager();

            // Table view aspect
            TableView.RowHeight      = AlbumRowHeight;
            TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
            TableView.Source         = new GMAlbumsViewTableViewSource(this);

            // Buttons
            var barButtonItemAttributes = new UITextAttributes
            {
                Font = UIFont.FromName(_picker.PickerFontName, _picker.PickerFontHeaderSize)
            };

            var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel");

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(cancelTitle,
                                                                   UIBarButtonItemStyle.Plain,
                                                                   Dismiss);

            if (_picker.UseCustomFontForNavigationBar)
            {
                NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
                NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
            }

            if (_picker.AllowsMultipleSelection)
            {
                var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done");
                NavigationItem.RightBarButtonItem = new UIBarButtonItem(doneTitle,
                                                                        UIBarButtonItemStyle.Done,
                                                                        FinishPickingAssets);
                if (_picker.UseCustomFontForNavigationBar)
                {
                    NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
                    NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
                }
                NavigationItem.RightBarButtonItem.Enabled = !_picker.AutoDisableDoneButton || _picker.SelectedAssets.Any();
            }

            // Bottom toolbar
            ToolbarItems = _picker.GetToolbarItems();

            // Title
            Title = _picker.Title ?? "picker.navigation.title".Translate(defaultValue: "Navigation bar default title");

            // Fetch PHAssetCollections
            var topLevelUserCollections = PHCollection.FetchTopLevelUserCollections(null);
            var smartAlbums             = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null);

            _collectionsFetchResults = new List <PHFetchResult> {
                topLevelUserCollections, smartAlbums
            };
            _collectionsLocalizedTitles = new List <string> {
                "picker.table.user-albums-header".Translate(defaultValue: "Albums"), "picker.table.smart-albums-header".Translate("Smart Albums")
            };

            UpdateFetchResults();

            // Register for changes
            PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this);
        }
Пример #2
0
 private void SetupToolbar()
 {
     ToolbarItems = _picker.GetToolbarItems();
 }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			_picker = (GMImagePickerController) NavigationController.ParentViewController;
			View.BackgroundColor = _picker.PickerBackgroundColor;

			// Navigation bar customization
			if (!string.IsNullOrWhiteSpace (_picker.CustomNavigationBarPrompt)) {
				NavigationItem.Prompt = _picker.CustomNavigationBarPrompt;
			}

			_imageManager = new PHCachingImageManager ();

			// Table view aspect
			TableView.RowHeight = AlbumRowHeight;
			TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
			TableView.Source = new GMAlbumsViewTableViewSource (this);

			// Buttons
			var barButtonItemAttributes = new UITextAttributes {
				Font = UIFont.FromName(_picker.PickerFontName, _picker.PickerFontHeaderSize)
			};
					
			var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel");
			NavigationItem.LeftBarButtonItem = new UIBarButtonItem (cancelTitle,
				UIBarButtonItemStyle.Plain,
				Dismiss);

			if (_picker.UseCustomFontForNavigationBar) {
				NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
				NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
			}

			if (_picker.AllowsMultipleSelection) {
				var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done");
				NavigationItem.RightBarButtonItem = new UIBarButtonItem (doneTitle,
					UIBarButtonItemStyle.Done,
					FinishPickingAssets);
				if (_picker.UseCustomFontForNavigationBar) {
					NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
					NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
				}
				NavigationItem.RightBarButtonItem.Enabled = _picker.AutoDisableDoneButton ? _picker.SelectedAssets.Any () : true;
			}

			// Bottom toolbar
			ToolbarItems = _picker.GetToolbarItems();

			// Title
			Title = _picker.Title ?? "picker.navigation.title".Translate(defaultValue: "Navigation bar default title");

			// Fetch PHAssetCollections
			var topLevelUserCollections = PHCollectionList.FetchTopLevelUserCollections(null);
			var smartAlbums = PHAssetCollection.FetchAssetCollections (PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null);
			_collectionsFetchResults = new List<PHFetchResult> { topLevelUserCollections, smartAlbums };
			_collectionsLocalizedTitles = new List<string> { "picker.table.user-albums-header".Translate (defaultValue: "Albums"), "picker.table.smart-albums-header".Translate("Smart Albums") };

			UpdateFetchResults ();

			// Register for changes
			PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this);

			if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) {
				EdgesForExtendedLayout = UIRectEdge.None;
			}
		}