2016-11-21 2 views
1

내 검색 표시 줄에서 '취소'버튼을 숨기려고했습니다. 다음의 커스텀 렌더러 코드를 구현했지만 작동하지 않는 것 같습니다. 누구든지 해결책을 알고 있다면 공유하십시오. layoutsubviews 방법에서 취소 버튼을 숨길 수Xamarin iOS 검색 창에서 취소 버튼 숨기기

protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e) 
    { 
     base.OnElementChanged(e); 
     if (Control != null) 
     { 
      Control.Subviews[0].Subviews[0].RemoveFromSuperview();   
     } 
    } 

답변

0

에서

public class iOSSearchBar : SearchBarRenderer 
    { 
     protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> args) 
     { 
      base.OnElementChanged(args); 

     UISearchBar bar = (UISearchBar)this.Control; 

     bar.AutocapitalizationType = UITextAutocapitalizationType.None; 
     bar.AutocorrectionType = UITextAutocorrectionType.No; 
     //bar.BarStyle = UIBarStyle.Default; 
     //bar.BarTintColor = UIColor.LightGray; 
     //bar.KeyboardType = UIKeyboardType.ASCIICapable; 
     bar.SearchBarStyle = UISearchBarStyle.Minimal; 
     bar.SetShowsCancelButton(false, false); 
     bar.ShowsCancelButton = false; 
} 
} 

덕분에 나는 내가 수동으로 제거하는 관리 생각합니다.

public override void LayoutSubviews() 
      { 
       base.LayoutSubviews(); 
       UISearchBar bar = (UISearchBar)this.Control; 
       bar.ShowsCancelButton = false; 

      } 

도 노력하고 팔로우하거나 내게 필요가 수색자를 서브 클래 싱 없음 : 이것은 나를 위해 일한

SearchBar.TextChanged += delegate 
      { 
       SearchBar.ShowsCancelButton = false; 

      }; 
1

. https://gist.github.com/xleon/9f94a8482162460ceaf9

using System; 
using Xamarin.Forms.Platform.iOS; 
using Xamarin.Forms; 
using UIKit; 
using System.Diagnostics; 

[assembly: ExportRenderer(typeof(SearchBar), typeof(Namespace.iOS.Renderers.ExtendedSearchBarRenderer))] 
namespace Namespace.iOS.Renderers 
{ 
    public class ExtendedSearchBarRenderer : SearchBarRenderer 
    { 
     protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
     { 
      base.OnElementPropertyChanged(sender, e); 

      if (e.PropertyName == "Text") 
      { 
       Control.ShowsCancelButton = false; 
      } 
     } 
    } 
}