草庐IT

uicontrolstate

全部标签

swift - 如何以编程方式在 SWIFT 中设置 UIImage 的 alpha?

我在这里找到了很多解决方案,但不是针对Swift的,而且我知道您可以使用UIImageView做到这一点,但在我的例子中,我需要一个以编程方式为设置alpha透明背景图像界面按钮。最好是UIImage扩展!letimg=UIImage(named:"imageWithoutAlpha")varimgInsets=UIEdgeInsetsMake(0,24,0,24)image=image!.resizableImageWithCapInsets(imgInsets)letmyButton=UIButton(frame:CGRect(x:50,y:50,width:img!.size.w

swift - setTitle(_ title : String? , for state : UIControlState) where is . 正常状态?

这个问题在这里已经有了答案:UIControlState.NormalisUnavailable(4个答案)关闭6年前。我正在使用Xcode8上的iOS10将我的应用程序更新到Swift3我得到一个错误:Btn.setTitle('str',forState:.Normal).Normal不再是UIControlState的枚举类型。我应该为此状态使用哪种类型的UIControlState?Apple枚举现在定义为publicstructUIControlState:OptionSet{publicinit(rawValue:UInt)publicstaticvarhighlighte

ios - 为什么 UIControlState 是结构而不是枚举?

我对UIControlState的运作方式有点困惑。具体来说,如果我看下面的例子:sender.setTitle("NewTitle",for:UIControlState.normal)我知道这会设置按钮(发件人)正常状态的标题。我原以为.normal是UIControlState类型的枚举值,但后来了解到它是一个具有常量的结构。第一个问题:如果目的只是为了传递一个状态,为什么不将其定义为枚举,而.normal是其中一种情况?其次,当我查看UIStateControl的文档时,我看到的只是“常量”的定义,例如:staticvarnormal:UIControlState第二/第三个问

ios - 我可以为自己的控件使用 UIControlState 的自定义值吗?

有没有办法为UIControl设置自定义状态——而不是现有的UIControlState值之一?在UIControlSate枚举中,有16位可用于自定义控件状态:UIControlStateApplication=0x00FF0000,//additionalflagsavailableforapplicationuse问题是UIControl的state属性是readonly。我想为自定义状态的UIButton设置不同的背景图片。 最佳答案 您可以在UIControl的子类中使用自定义状态。创建一个名为customState的变量

ios - UIButton的UIControlState "application"有什么用?

我浏览了appledoc也是,但它只是说明它Additionalcontrol-stateflagsavailableforapplicationuse.它只是一个getter方法,所以它什么时候设置? 最佳答案 application和reserved基本上是标记。在查看它们的objective-c文档时,这一点更加清楚:disabled:UIControlStateDisabled=1application:UIControlStateApplication=0x00FF0000reserved:UIControlStateRe

ios - 配置对象时 `UIControlState()`和 `UIControlState.normal`有什么区别

我经常看到使用UIControlState.normal,例如在UIButton对象上设置一个titleColor,它将在所有控件状态中使用,作为UIButton。setTitleColor文档说:Ingeneral,ifapropertyisnotspecifiedforastate,thedefaultistousethenormalvalue.Ifthenormalvalueisnotset,thenthepropertydefaultstoasystemvalue.Therefore,ataminimum,youshouldsetthevalueforthenormalstat

ios - UIControlState.Normal 不可用

以前对于UIButton实例,您可以为setTitle或setImage传入UIControlState.Normal。.Normal不再可用,我应该用什么代替?letbtn=UIButton(frame:CGRect(x:0,y:0,width:20,height:20))btn.setTitle("title",for:.Normal)//doesnotcompile(这是一个规范的问答对,以防止与此UIButton和UIControliOS10和Swift3更改相关的重复问题泛滥) 最佳答案 swift3更新:看起来Xcode