草庐IT

UIBUTTON

全部标签

ios - 坚持以编程方式将目标添加到按钮

我创建了一个UIButton,我希望它在按下时打印一些消息。所以我做了这样的事情:在loadView()中button.addTarget(self,action:#selector(ViewController.pressButton(button:)),for:.touchUpInside)一个方法:funcpressButton(button:UIButton){NSLog("pressed!")}但是当我点击按钮时没有任何反应。 最佳答案 在您的viewDidLoad中添加按钮代码,它将为您工作:overridefuncvi

ios - 突出显示/选定状态问题的 UIButton 背景颜色

我有一个UIButton并且我创建了一个扩展来为不同的状态添加背景颜色。我正在使用以下代码:extensionUIButton{funcsetBackgroundColor(color:UIColor,forState:UIControlState){UIGraphicsBeginImageContext(CGSize(width:1,height:1))CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),color.CGColor)CGContextFillRect(UIGraphicsGetCurrentCont

ios - 突出显示/选定状态问题的 UIButton 背景颜色

我有一个UIButton并且我创建了一个扩展来为不同的状态添加背景颜色。我正在使用以下代码:extensionUIButton{funcsetBackgroundColor(color:UIColor,forState:UIControlState){UIGraphicsBeginImageContext(CGSize(width:1,height:1))CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),color.CGColor)CGContextFillRect(UIGraphicsGetCurrentCont

ios - Swift - 在应用程序中打开网页,按钮没有反应

我创建了一个按钮来从应用中调用电话:@IBActionfunccallButton(sender:AnyObject){if(PhoneNumber!=""){UIApplication.sharedApplication().openURL(NSURL(string:"telprompt://\(PhoneNumber)")!)}}而且它工作得很好。当我想打开网页时会发生奇怪的事情。我使用几乎完全相同的代码@IBActionfuncopenWeb(sender:AnyObject){UIApplication.sharedApplication().openURL(NSURL(str

ios - Swift - 在应用程序中打开网页,按钮没有反应

我创建了一个按钮来从应用中调用电话:@IBActionfunccallButton(sender:AnyObject){if(PhoneNumber!=""){UIApplication.sharedApplication().openURL(NSURL(string:"telprompt://\(PhoneNumber)")!)}}而且它工作得很好。当我想打开网页时会发生奇怪的事情。我使用几乎完全相同的代码@IBActionfuncopenWeb(sender:AnyObject){UIApplication.sharedApplication().openURL(NSURL(str

swift - 更改 UINavigationbar 中元素的色调颜色(iOS 11)

我一直在使用这段代码来改变导航栏中元素的色调:UINavigationBar.appearance().tintColor=theme.labelColor但是,这在iOS11中不再有效。在iOS11之前,导航栏中的按钮是UINavigationButton,但在iOS11中它们已更改为_UIModernBarButton。我可以使用UIButton.appearance().tintcolor更改它们的色调,但这会改变每个按钮的颜色。这是一个比较:任何人都知道如何更改导航栏中的按钮色调颜色?2017年1月9日更新:看起来_UIButtonBarButton具有正确的色调,但_UIMo

swift - 更改 UINavigationbar 中元素的色调颜色(iOS 11)

我一直在使用这段代码来改变导航栏中元素的色调:UINavigationBar.appearance().tintColor=theme.labelColor但是,这在iOS11中不再有效。在iOS11之前,导航栏中的按钮是UINavigationButton,但在iOS11中它们已更改为_UIModernBarButton。我可以使用UIButton.appearance().tintcolor更改它们的色调,但这会改变每个按钮的颜色。这是一个比较:任何人都知道如何更改导航栏中的按钮色调颜色?2017年1月9日更新:看起来_UIButtonBarButton具有正确的色调,但_UIMo

ios - 将 UILabel 的某些部分变成 UIButton?

这个问题在这里已经有了答案:Createtap-able"links"intheNSAttributedStringofaUILabel?(37个答案)关闭5年前。我有一个属性字符串UILabel,我能够为文本的某些部分着色lettext="Whydid\(event)give\(event2)a5starsreview?Detailshere."letlinkTextWithColor="Whydid"letrange=(textasNSString).rangeOfString(linkTextWithColor)letattributedString=NSMutableAttri

ios - 将 UILabel 的某些部分变成 UIButton?

这个问题在这里已经有了答案:Createtap-able"links"intheNSAttributedStringofaUILabel?(37个答案)关闭5年前。我有一个属性字符串UILabel,我能够为文本的某些部分着色lettext="Whydid\(event)give\(event2)a5starsreview?Detailshere."letlinkTextWithColor="Whydid"letrange=(textasNSString).rangeOfString(linkTextWithColor)letattributedString=NSMutableAttri

ios - 如何循环遍历我的 Swift View 中的所有 UIButton?

我如何在Swift的View中循环遍历所有UIButtons?我想将所有标题设置为"",但我在Swift中的for循环出错。forbtnsinself.viewas[UIButton]{//setthetitleto""} 最佳答案 这段代码应该可以工作:forviewinself.view.subviewsas[UIView]{ifletbtn=viewas?UIButton{btn.setTitleForAllStates("")}}您需要遍历subViews数组。 关于ios-如何