2016-04-14 8 views
0

を取得し、私はこのようになりますカスタムEntryRenderer内部方法OnElementChangedオーバーライドされました:私がやりたいすべてのFontAwesomeアイコンを追加するには入場コントロールをカスタマイズでCustomRendererでのコントロールの寸法(Xamarin.Forms iOS版)

protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
{ 
    base.OnElementChanged(e); 

    if (Control != null) 
    { 
     var iconLabel = new UILabel(); 
     iconLabel.Font = FontAwesome.Font(12); 
     iconLabel.Text = " " + FontAwesome.FAPlay; 
     iconLabel.Frame = new CGRect(x: 5, y: 0, width: 20, height: 20); 
     Control.LeftView = iconLabel; 
     Control.LeftViewMode = UITextFieldViewMode.Always; 

     Control.BorderStyle = UITextBorderStyle.None; 
     var bottomLine = new CALayer(); 
     bottomLine.Frame = new CGRect(0.0, Control.Frame.Height - 1, Control.Frame.Width, 1.0); 
     bottomLine.BackgroundColor = UIColor.White.CGColor; 
     Control.Layer.AddSublayer(bottomLine); 
    } 
} 

を左端にレイヤーを追加してボトムボーダーしか持たないようにします。

Control.Frameは、Width & Height(その値は0)を持たないという問題があります。

ボーダーボトムエントリ(UITextField)スタイルをハックするためのヘルプや別の方法はありますか? ありがとうございます。

+0

:-)

(Xamarin 'Entry'である)' e.N​​ewElement'がない場合は多分あなたもチェックできますnullを適用してそのディメンションを適用しますか –

+0

@GeraldVersluisがそれを試みましたが、うまくいきませんでした。 –

答えて

3

私がしたいのは、左側にFontAwesomeアイコンを追加するようにEntryコントロールをカスタマイズし、下部にボーダーボーダーしかないようにレイヤーを追加することです。

UIViewをコントロールのSubviewとして追加して、クリッピングが処理されます。

enter image description here

if (Control != null) { 
    Control.BackgroundColor = UIColor.LightGray; 
    var iconLabel = new UILabel(); 
    iconLabel.Font = FontAwesome.Font(12); 
    iconLabel.Text = " " + FontAwesome.FAAmbulance; 
    iconLabel.Frame = new CGRect(x: 5, y: 0, width: 20, height: 20); 
    Control.LeftView = iconLabel; 
    Control.LeftViewMode = UITextFieldViewMode.Always; 

    Control.BorderStyle = UITextBorderStyle.None; 
    Console.WriteLine ("cs: " + customSize); 
    UIView myBox = new UIView (new CGRect (0.0, 20.0, 1000.0, 1.0)); 
    myBox.BackgroundColor = UIColor.Red; 
    Control.AddSubview(myBox); 
} 

enter image description here

if (Control != null) { 
    var iconLabel = new UILabel(); 
    iconLabel.Font = FontAwesome.Font(12); 
    iconLabel.Text = " " + FontAwesome.FAPlay; 
    iconLabel.Frame = new CGRect(x: 5, y: 0, width: 20, height: 20); 
    Control.LeftView = iconLabel; 
    Control.LeftViewMode = UITextFieldViewMode.Always; 

    Control.BorderStyle = UITextBorderStyle.None; 
    Console.WriteLine ("cs: " + customSize); 
    UIView myBox = new UIView (new CGRect (0.0, 20.0, 1000.0, 1.0)); 
    myBox.BackgroundColor = UIColor.Black; 
    Control.AddSubview(myBox); 
} 
+0

ありがとう!魅力的なものとして働いた:)ちょうど、あなたは効果を見るためにパディングを右側に置かなければならないことに注意しなければならない。さもなければ、それはエントリーの無限のように見えるだろう:) –

+0

それはあなたのために働いた。はい、パディングについてのあなたの権利... – SushiHangover

+0

これは古い答えです。しかし、パディングをどのように追加しましたか教えてください。 –

関連する問題