Xamarin - Gradient background

后端 未结 2 1667
长发绾君心
长发绾君心 2021-01-19 06:40

I\'m trying to programmatically set a background gradient like this in Xamarin iOS:

CGColor[] colors = new CGColor[] { new UIColor(red: 0.05f, green:0.44f, b         


        
2条回答
  •  醉梦人生
    2021-01-19 07:11

    Your gradient layer that is assign to the root View of the ViewController is being displayed "behind" all the other Views.

    By default, views (UILabel, UIButton, etc) do not have a background color set and thus will blend with that background layer, if that is not the effect that you are looking for assign a background to them:

    var button = new UIButton(UIButtonType.System);
    button.Frame = new CGRect(40, 300, 120, 40);
    button.SetTitle("No Background", UIControlState.Normal);
    button.TintColor = UIColor.Red;
    View.AddSubview(button);
    
    var button2 = new UIButton(UIButtonType.System);
    button2.Frame = new CGRect(180, 300, 100, 40);
    button2.SetTitle("Background", UIControlState.Normal);
    button2.TintColor = UIColor.Red;
    button2.BackgroundColor = UIColor.White;
    View.AddSubview(button2);
    

提交回复
热议问题