UIButton属性bug

本文介绍了UIButton中字体和颜色的正确设置方法。指出titleLabel的text和textColor属性不能直接用于设置按钮显示的文本和颜色,并提供了正确的设置示例。

无效用法

but2.titleLabel.text    不可以用来按键显示字体,用法未知

button1.titleLabel.textColor 不可用来设置按键字体颜色,用法未知;

button1.titleLabel.font  可以用来设置按键字体大小

设置按键显示字体方法:

[button1 setTitle:@"标题1" forState:UIControlStateNormal];

设置按键字体颜色方法:

[button1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

#if USE_UNI_LUA using LuaAPI = UniLua.Lua; using RealStatePtr = UniLua.ILuaState; using LuaCSFunction = UniLua.CSharpFunctionDelegate; #else using LuaAPI = XLua.LuaDLL.Lua; using RealStatePtr = System.IntPtr; using LuaCSFunction = XLua.LuaDLL.lua_CSFunction; #endif using XLua; using System.Collections.Generic; namespace CSObjectWrap { public class UIButtonWrap { public static void __Register(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); Utils.BeginObjectRegister(typeof(UIButton), L, translator, 0, 2, 12, 12); Utils.RegisterFunc(L, Utils.METHOD_IDX, "SetState", SetState); Utils.RegisterFunc(L, Utils.METHOD_IDX, "setOnPressScaleEnable", setOnPressScaleEnable); Utils.RegisterFunc(L, Utils.GETTER_IDX, "isEnabled", get_isEnabled); Utils.RegisterFunc(L, Utils.GETTER_IDX, "normalSprite", get_normalSprite); Utils.RegisterFunc(L, Utils.GETTER_IDX, "normalSprite2D", get_normalSprite2D); Utils.RegisterFunc(L, Utils.GETTER_IDX, "dragHighlight", get_dragHighlight); Utils.RegisterFunc(L, Utils.GETTER_IDX, "hoverSprite", get_hoverSprite); Utils.RegisterFunc(L, Utils.GETTER_IDX, "pressedSprite", get_pressedSprite); Utils.RegisterFunc(L, Utils.GETTER_IDX, "disabledSprite", get_disabledSprite); Utils.RegisterFunc(L, Utils.GETTER_IDX, "hoverSprite2D", get_hoverSprite2D); Utils.RegisterFunc(L, Utils.GETTER_IDX, "pressedSprite2D", get_pressedSprite2D); Utils.RegisterFunc(L, Utils.GETTER_IDX, "disabledSprite2D", get_disabledSprite2D); Utils.RegisterFunc(L, Utils.GETTER_IDX, "pixelSnap", get_pixelSnap); Utils.RegisterFunc(L, Utils.GETTER_IDX, "onClick", get_onClick); Utils.RegisterFunc(L, Utils.SETTER_IDX, "isEnabled", set_isEnabled); Utils.RegisterFunc(L, Utils.SETTER_IDX, "normalSprite", set_normalSprite); Utils.RegisterFunc(L, Utils.SETTER_IDX, "normalSprite2D", set_normalSprite2D); Utils.RegisterFunc(L, Utils.SETTER_IDX, "dragHighlight", set_dragHighlight); Utils.RegisterFunc(L, Utils.SETTER_IDX, "hoverSprite", set_hoverSprite); Utils.RegisterFunc(L, Utils.SETTER_IDX, "pressedSprite", set_pressedSprite); Utils.RegisterFunc(L, Utils.SETTER_IDX, "disabledSprite", set_disabledSprite); Utils.RegisterFunc(L, Utils.SETTER_IDX, "hoverSprite2D", set_hoverSprite2D); Utils.RegisterFunc(L, Utils.SETTER_IDX, "pressedSprite2D", set_pressedSprite2D); Utils.RegisterFunc(L, Utils.SETTER_IDX, "disabledSprite2D", set_disabledSprite2D); Utils.RegisterFunc(L, Utils.SETTER_IDX, "pixelSnap", set_pixelSnap); Utils.RegisterFunc(L, Utils.SETTER_IDX, "onClick", set_onClick); Utils.EndObjectRegister(typeof(UIButton), L, translator, null, null, null, null, null); Utils.BeginClassRegister(typeof(UIButton), L, __CreateInstance, 1, 1, 1); Utils.RegisterObject(L, translator, Utils.CLS_IDX, "UnderlyingSystemType", typeof(UIButton)); Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "current", get_current); Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, "current", set_current); Utils.EndClassRegister(typeof(UIButton), L, translator); } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int __CreateInstance(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { if(LuaAPI.lua_gettop(L) == 1) { UIButton __cl_gen_ret = new UIButton(); translator.Push(L, __cl_gen_ret); return 1; } } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return LuaAPI.luaL_error(L, "invalid arguments to UIButton constructor!"); } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int SetState(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); try { { UIButtonColor.State state;translator.Get(L, 2, out state); bool immediate = LuaAPI.lua_toboolean(L, 3); __cl_gen_to_be_invoked.SetState( state, immediate ); return 0; } } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int setOnPressScaleEnable(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); try { { bool enable = LuaAPI.lua_toboolean(L, 2); __cl_gen_to_be_invoked.setOnPressScaleEnable( enable ); return 0; } } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_isEnabled(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushboolean(L, __cl_gen_to_be_invoked.isEnabled); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_normalSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushstring(L, __cl_gen_to_be_invoked.normalSprite); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_normalSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); translator.Push(L, __cl_gen_to_be_invoked.normalSprite2D); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_current(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { translator.Push(L, UIButton.current); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_dragHighlight(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushboolean(L, __cl_gen_to_be_invoked.dragHighlight); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_hoverSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushstring(L, __cl_gen_to_be_invoked.hoverSprite); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_pressedSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushstring(L, __cl_gen_to_be_invoked.pressedSprite); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_disabledSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushstring(L, __cl_gen_to_be_invoked.disabledSprite); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_hoverSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); translator.Push(L, __cl_gen_to_be_invoked.hoverSprite2D); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_pressedSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); translator.Push(L, __cl_gen_to_be_invoked.pressedSprite2D); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_disabledSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); translator.Push(L, __cl_gen_to_be_invoked.disabledSprite2D); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_pixelSnap(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushboolean(L, __cl_gen_to_be_invoked.pixelSnap); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int get_onClick(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); translator.Push(L, __cl_gen_to_be_invoked.onClick); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 1; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_isEnabled(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.isEnabled = LuaAPI.lua_toboolean(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_normalSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.normalSprite = LuaAPI.lua_tostring(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_normalSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.normalSprite2D = (UnityEngine.Sprite)translator.GetObject(L, 2, typeof(UnityEngine.Sprite)); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_current(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton.current = (UIButton)translator.GetObject(L, 1, typeof(UIButton)); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_dragHighlight(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.dragHighlight = LuaAPI.lua_toboolean(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_hoverSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.hoverSprite = LuaAPI.lua_tostring(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_pressedSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.pressedSprite = LuaAPI.lua_tostring(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_disabledSprite(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.disabledSprite = LuaAPI.lua_tostring(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_hoverSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.hoverSprite2D = (UnityEngine.Sprite)translator.GetObject(L, 2, typeof(UnityEngine.Sprite)); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_pressedSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.pressedSprite2D = (UnityEngine.Sprite)translator.GetObject(L, 2, typeof(UnityEngine.Sprite)); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_disabledSprite2D(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.disabledSprite2D = (UnityEngine.Sprite)translator.GetObject(L, 2, typeof(UnityEngine.Sprite)); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_pixelSnap(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.pixelSnap = LuaAPI.lua_toboolean(L, 2); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int set_onClick(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { UIButton __cl_gen_to_be_invoked = (UIButton)translator.FastGetCSObj(L, 1); __cl_gen_to_be_invoked.onClick = (System.Collections.Generic.List<EventDelegate>)translator.GetObject(L, 2, typeof(System.Collections.Generic.List<EventDelegate>)); } catch(System.Exception __gen_e) { return LuaAPI.luaL_error(L, "c# exception:" + __gen_e); } return 0; } } } Assets/XLua/Gen/UIButtonWrap.cs(142,44): error CS1061: Type `UIButton' does not contain a definition for `setOnPressScaleEnable' and no extension method `setOnPressScaleEnable' of type `UIButton' could be found (are you missing a using directive or an assembly reference?)
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值