Beispiel #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> args)
        {
            base.OnElementChanged(args);

            UISearchBar bar = Control;

            bar.ShowsCancelButton = false;
            bar.SearchBarStyle    = UISearchBarStyle.Minimal;
            bar.SetImageforSearchBarIcon(UIImage.FromBundle("location"), UISearchBarIcon.Search, UIControlState.Normal);


            Foundation.NSString _searchField = new Foundation.NSString("searchField");
            var textFieldInsideSearchBar     = ( UITextField )bar.ValueForKey(_searchField);

            textFieldInsideSearchBar.BorderStyle        = UITextBorderStyle.None;
            textFieldInsideSearchBar.ClipsToBounds      = true;
            textFieldInsideSearchBar.Layer.BorderWidth  = 0.3f;
            textFieldInsideSearchBar.Layer.CornerRadius = 5f;
            textFieldInsideSearchBar.Layer.BorderColor  = UIColor.LightGray.CGColor;
            textFieldInsideSearchBar.BackgroundColor    = UIColor.White;
        }
Beispiel #2
0
        public static void SetupStyle(this UISearchBar view, Models.ThemeConfigs.SearchBar model)
        {
            if (view is BindableSearchBar)
            {
                ((BindableSearchBar)view).IsShowCancelOnEditing = true;
            }

            view.BackgroundColor = (UIColor)model.BackgroundColor;
            view.BarTintColor    = (UIColor)model.BackgroundColor;
            view.TintColor       = (UIColor)model.TextField.TextColor;

            if (model.SearchImage != null)
            {
                view.SetImageforSearchBarIcon(ImageCache.GetImage(model.SearchImage.Path, (UIColor)model.TextField.Placeholder.TextColor), UISearchBarIcon.Search, UIControlState.Normal);
            }

            view.Layer.BorderWidth = 0f;
            view.Layer.BorderColor = view.BackgroundColor.CGColor;

            view.BackgroundImage = model.BackgroundColor.ToUIImage();
            view.SetBackgroundImage(
                model.BackgroundColor.ToUIImage(),
                UIBarPosition.Any,
                UIBarMetrics.Default
                );

            var searchTextField = view.ValueForKey(new NSString("_searchField")) as UITextField;

            if (searchTextField != null)
            {
                searchTextField.BackgroundColor       = (UIColor)model.TextField.Background;
                searchTextField.Font                  = (UIFont)model.TextField.Font;
                searchTextField.TextColor             = (UIColor)model.TextField.TextColor;
                searchTextField.TintColor             = (UIColor)model.TextField.TintColor;
                searchTextField.AttributedPlaceholder = new NSMutableAttributedString(Mvx.Resolve <ILocalizationService>().GetLocalizableString("Base", "Search"), (UIFont)model.TextField.Placeholder.Font, (UIColor)model.TextField.Placeholder.TextColor);
            }
        }