Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin iOS全球风格_Xamarin_Xamarin.ios - Fatal编程技术网

Xamarin iOS全球风格

Xamarin iOS全球风格,xamarin,xamarin.ios,Xamarin,Xamarin.ios,我正在开发Xamarin iOS应用程序 是否可以在Xamarin iOS应用程序(如Xamarin Android应用程序)中创建全局样式(例如按钮) 有什么想法吗?苹果公司提供了可以用于此目的的想法。 官方的Xamarin开发者门户上有一个关于它的网站 其背后的思想是,您可以在控件上使用静态方法来设置所需的外观,例如: UIButton.Appearance.TintColor=UIColor.LightGray; UIButton.Appearance.SetTitleColor(UICo

我正在开发Xamarin iOS应用程序

是否可以在Xamarin iOS应用程序(如Xamarin Android应用程序)中创建全局样式(例如按钮)

有什么想法吗?

苹果公司提供了可以用于此目的的想法。
官方的Xamarin开发者门户上有一个关于它的网站

其背后的思想是,您可以在控件上使用静态方法来设置所需的外观,例如:

UIButton.Appearance.TintColor=UIColor.LightGray;
UIButton.Appearance.SetTitleColor(UIColor.FromRGB(0127,14),UIControlState.Normal);

在其中创建一个控件集公共主题

比如说

public class CustomTextField : UITextField
{
    public UIView RightViewEnabled
    {
        get;
        set;
    }

    public UIView RightViewDisabled
    {
        get;
        set;
    }

    public override CoreGraphics.CGRect LeftViewRect(CoreGraphics.CGRect forBounds)
    {
        var rect = base.LeftViewRect(forBounds);
        rect.X += 10;
        //rect.Y -= 2;
        return rect;
    }

    public override CoreGraphics.CGRect RightViewRect(CoreGraphics.CGRect forBounds)
    {
        var rect = base.RightViewRect(forBounds);
        rect.X -= 10;
        return rect;
    }

    public override CoreGraphics.CGRect TextRect(CoreGraphics.CGRect forBounds)
    {
        var rect = base.TextRect(forBounds);
        if (LeftView != null)
            rect.X += 5;
        if (RightView != null)
            rect.Width -= 10;
        return rect;
    }


    public override CoreGraphics.CGRect EditingRect(CoreGraphics.CGRect forBounds)
    {
        var rect = base.EditingRect(forBounds);
        if (LeftView != null)
            rect.X += 5;
        //if (RightView != null)
        //    rect.X -= 10;
        return rect;
    }

    public override bool Enabled
    {
        get 
        {
            return base.Enabled;
        }
        set
        {
            base.Enabled = value;
            if (value)
            {
                if (RightViewEnabled != null)
                    RightView = RightViewEnabled;
                base.TextColor = _textColor;
            }
            else
            {
                if (RightViewDisabled != null)
                    RightView = RightViewDisabled;
                if (TextColorDisabled != null)
                    base.TextColor = TextColorDisabled;
            }
        }
    }

    public UIColor TextColorDisabled
    {
        get;
        set;
    }

    private UIColor _textColor;

    public override UIColor TextColor
    {
        get
        {
            return base.TextColor;
        }
        set
        {
            _textColor = value;
            base.TextColor = value;
        }
    }

    public Guid ValueId
    {
        get;
        set;
    }

    public override bool CanPerform(ObjCRuntime.Selector action, Foundation.NSObject withSender)
    {
        if (action == new Selector("paste:") || action == new Selector("cut:") || action == new Selector("copy:")
             || action == new Selector("select:") || action == new Selector("selectAll:") || action == new Selector("delete:") || action == new Selector("_promptForReplace:")
             || action == new Selector("_transliterateChinese:") || action == new Selector("_showTextStyleOptions:") || action == new Selector("_define:") || action == new Selector("_addShortcut:")
             || action == new Selector("_accessibilitySpeak:") || action == new Selector("_accessibilitySpeakLanguageSelection:") || action == new Selector("_accessibilityPauseSpeaking:") || action == new Selector("makeTextWritingDirectionRightToLeft:")
             || action == new Selector("makeTextWritingDirectionLeftToRight:") || action == new Selector("_share:"))
            return false;
        else
            return base.CanPerform(action, withSender);
    }
}

Xamarin文档中有一个专门针对全局样式的页面,我建议在下次发布之前搜索文档,因为你会得到一个更快的答案:)@ElliotBlackburn,作者没有提到Xamarin表单的用法。@EvZ fair point,我一定错过了,我的错,谢谢你指出。